Logger#
This module provides a function to create a logger, that is ready to successfully log information in AWS Lambdas or ECS where without the appropriate configuration your logs will not show up in CloudWatch.
- core_mixins.logger.get_logger(logger_name: str | None = None, log_level: int = 20, propagate: bool = True, stream_handler: TextIO | None = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, formatter: str = '[%(levelname)s] %(message)s', reset_handlers: bool = False) Logger[source]#
It returns a logger or create it if it doesn’t exist. If the logger name is not specified, it returns the root logger….
A handler is only added when the logger has none yet, so repeated module-level calls (e.g.
logger = get_logger(__name__)) never accumulate duplicate handlers. Passreset_handlers=Trueto intentionally replace the existing handler (e.g. to change the formatter or stream).- Parameters:
logger_name – Logger’s name or None for root logger.
log_level – The logging level (CRITICAL = 50, ERROR = 40, WARNING = 30, INFO = 20)
stream_handler – A handler which writes logging records, appropriately formatted to a stream.
formatter – It specifies the layout of log records in the final output. It defines the structure of log messages by specifying a format string that includes placeholders for various attributes of a log record, such as timestamp, log level, logger name, and the log message itself…
propagate – It determines whether a log message should be passed to the handlers of higher-level (ancestor) loggers.This can be useful in situations where you want to control the flow of log messages and avoid duplication in the log output (like Lambda Functions)…
reset_handlers – When
True, existing handlers are removed before adding the new one, allowing the logger to be reconfigured with a different stream or formatter.
- Returns:
The logger.