nvflare.fuel.utils.log_utils module¶
- class ANSIColor[source]¶
Bases:
object
- COLORS = {'black': '30', 'blue': '34', 'bold_red': '31;1', 'cyan': '36', 'green': '32', 'grey': '38', 'magenta': '35', 'red': '31', 'reset': '0', 'white': '37', 'yellow': '33'}¶
- DEFAULT_LEVEL_COLORS = {'CRITICAL': '31;1', 'DEBUG': '38', 'ERROR': '31', 'INFO': '38', 'NOTSET': '38', 'WARNING': '33'}¶
- class BaseFormatter(fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt=None, style='%')[source]¶
Bases:
Formatter
Default formatter for log records.
- The following attributes are added to the record and can be configured in fmt with ‘%(<attribute>)s’
record.name: base name
record.fullName: full name
record.fl_ctx: bracked fl ctx key value pairs if exists in the message
record.identity: identity from fl_ctx if fl_ctx exists
- Parameters:
fmt (str) – format string which uses LogRecord attributes.
datefmt (str) – date/time format string. Defaults to ‘%Y-%m-%d %H:%M:%S’.
style (str) – style character ‘%’ ‘{’ or ‘$’ for format string.
- format(record)[source]¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class ColorFormatter(fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt=None, style='%', level_colors={'CRITICAL': '31;1', 'DEBUG': '38', 'ERROR': '31', 'INFO': '38', 'NOTSET': '38', 'WARNING': '33'}, logger_colors={})[source]¶
Bases:
BaseFormatter
Format colors based on log levels. Optionally can provide mapping based on logger names.
- Parameters:
fmt (str) – format string which uses LogRecord attributes.
datefmt (str) – date/time format string. Defaults to ‘%Y-%m-%d %H:%M:%S’.
style (str) – style character ‘%’ ‘{’ or ‘$’ for format string.
level_colors (Dict[str, str]) – dict of levelname: ANSI color. Defaults to ANSIColor.DEFAULT_LEVEL_COLORS.
logger_colors (Dict[str, str]) – dict of loggername: ANSI color. Defaults to {}.
- format(record)[source]¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class JsonFormatter(fmt='%(asctime)s - %(identity)s - %(name)s - %(fullName)s - %(levelname)s - %(fl_ctx)s - %(message)s', datefmt=None, style='%')[source]¶
Bases:
BaseFormatter
Format log records into JSON.
- Parameters:
fmt (str) – format string which uses LogRecord attributes. Attributes are used for JSON keys.
datefmt (str) – date/time format string. Defaults to ‘%Y-%m-%d %H:%M:%S’.
style (str) – style character ‘%’ ‘{’ or ‘$’ for format string.
- format(record) str [source]¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class LogMode[source]¶
Bases:
object
- CONCISE = 'concise'¶
- FULL = 'full'¶
- RELOAD = 'reload'¶
- VERBOSE = 'verbose'¶
- class LoggerNameFilter(logger_names=['nvflare'], exclude_logger_names=[])[source]¶
Bases:
Filter
Filter log records based on logger names. Additionally allows all log records with levelno > logging.INFO through.
- Parameters:
logger_names (List[str]) – list of logger names to allow through filter
exclude_logger_names (List[str]) – list of logger names to disallow through filter (takes precedence over allowing from logger_names)