FancyLogger, a singleton logger with colour-coded console output and
an optional REST handler (RESTHandler) that forwards log records to a local
/api/receive endpoint when the FLOG environment variable is set. All
internal mellea modules obtain their logger via FancyLogger.get_logger().
Classes
CLASS RESTHandler
Logging handler that forwards records to a local REST endpoint.
Sends log records as JSON to /api/receive when the FLOG environment
variable is set. Failures are silently suppressed to avoid disrupting the
application.
Args:
api_url: The URL of the REST endpoint that receives log records.method: HTTP method to use when sending records (default"POST").headers: HTTP headers to send; defaults to\{"Content-Type"\: "application/json"\}whenNone.
FUNC emit
FLOG environment variable is set.
Silently suppresses any network or HTTP errors to avoid disrupting the application.
Args:
record: The log record to forward.
CLASS JsonFormatter
Logging formatter that serialises log records as structured JSON dicts.
Includes timestamp, level, message, module, function name, line number,
process ID, thread ID, and (if present) exception information.
Methods:
FUNC format
record: The log record to format.
CLASS CustomFormatter
A nice custom formatter copied from Sergey Pleshakov’s post on StackOverflow.
Attributes:
cyan: ANSI escape code for cyan text, used for DEBUG messages.grey: ANSI escape code for grey text, used for INFO messages.yellow: ANSI escape code for yellow text, used for WARNING messages.red: ANSI escape code for red text, used for ERROR messages.bold_red: ANSI escape code for bold red text, used for CRITICAL messages.reset: ANSI escape code to reset text colour.FORMATS: Mapping from logging level integer to the colour-formatted format string.
FUNC format
record: The log record to format.
- The formatted log record string with ANSI colour codes applied.
CLASS FancyLogger
Singleton logger with colour-coded console output and optional REST forwarding.
Obtain the shared logger instance via FancyLogger.get_logger(). Log level
defaults to INFO but can be raised to DEBUG by setting the DEBUG
environment variable. When the FLOG environment variable is set, records are
also forwarded to a local /api/receive REST endpoint via RESTHandler.
Attributes:
logger: The sharedlogging.Loggerinstance;Noneuntil first call toget_logger().CRITICAL: Numeric level for critical log messages (50).FATAL: Alias forCRITICAL(50).ERROR: Numeric level for error log messages (40).WARNING: Numeric level for warning log messages (30).WARN: Alias forWARNING(30).INFO: Numeric level for informational log messages (20).DEBUG: Numeric level for debug log messages (10).NOTSET: Numeric level meaning no level is set (0).