CustomLogFormatter#
- class dynode.utils.custom_log_formatter.CustomLogFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)#
Bases:
Formatter
Custom Log Formatter class that inherits Python’s logging.Formatter class.
CustomLogFormatter was created and intended for when a function is decorated with log_decorator(). It captures the decorated functions name and file name to include in the log.
For inline logging calls the CustomLogFormatter will behave exactly the same as logging.Formatter. Unless the user passes func_name_override and/or file_name_override attributes into logging.[log level](exra=[extra arguments])
Below parameters are passed to CustomLogFormatter when used and derive from logging.Formatter
Parameters#
- fmtstr, optional
A format string in the given style for the logged output as a whole. The possible mapping keys are drawn from the LogRecord object’s LogRecord attributes. If not specified, ‘%(message)s’ is used, which is just the logged message. Defaults to None.
- datefmtstr, optional
A format string in the given style for the date/time portion of the logged output. If not specified, the default described in formatTime() is used. Defaults to None.
- stylestr, optional
Can be one of ‘%’, ‘{’ or ‘$’ and determines how the format string will be merged with its data: using one of printf-style String Formatting (%), str.format() ({) or string.Template ($). This only applies to fmt and datefmt (e.g. ‘%(message)s’ versus ‘{message}’), not to the actual log messages passed to the logging methods. However, there are other ways to use {- and $-formatting for log messages. Defaults to ‘%’.
- validatebool, optional
If True (the default), incorrect or mismatched fmt and style will raise a ValueError; for example, logging.Formatter(‘%(asctime)s - %(message)s’, style=’{‘).
- defaultsdict[str, Any], optional
A dictionary with default values to use in custom fields. For example, logging.Formatter(‘%(ip)s %(message)s’, defaults={“ip”: None}). Defaults to None.
- __init__(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)#
Initialize the formatter with specified format strings.
Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument. If datefmt is omitted, you get an ISO8601-like (or RFC 3339-like) format.
Use a style parameter of ‘%’, ‘{’ or ‘$’ to specify that you want to use one of %-formatting,
str.format()
({}
) formatting orstring.Template
formatting in your format string.Changed in version 3.2: Added the
style
parameter.
Methods
format
(record)Override for logging Formatter format function.
Attributes