logging¶
The logging module
holds methods and decorators related to logging and loggers.
Functions¶
- logs_vars(logger: Logger, *ignore: str, start_message: str | None = None, start_message_level: str | int = 10, end_message: str | None = None, end_message_level: str | int = 10, var_message_level: str | int = 10)¶
A decorator which will log the variables of a function at the given level when the function is called. In the event that the wrapped function raises an exception, this decorator will log an error in the provided logger, and pass the exception up to the caller.
- Parameters:
logger – The Logger to log with.
ignore – Any parameters that should not be logged.
start_message – A message that gets logged before the function even starts executing
start_message_level – The level at which start_message should log. This defaults to logging.DEBUG.
end_message – A message that gets logged after the function stops executing (assuming no unexpected errors).
end_message_level – The level at which the end_message should log. This defaults to logging.DEBUG.
var_message_level – The level at which the variables should log. This defaults to logging.DEBUG.
- make_logger(name: str, /, env_var: str = 'LOG_LEVEL', *, log_to_file: str | None = None, default_level: str | int = 20, show_function: bool = False, **custom_levels: int) Logger ¶
This creates a logger with a few default settings as well as some custom levels, if specified. The format of messages for this logger should be
'{levelname}: {name} - {message}'
- Parameters:
name – The name of the logger.
env_var – The environment variable it should be linked to.
log_to_file – If this is specified, it should be the full file name for the logger to log to.
default_level –
This may be either a str or an int representing the desired log level. per python docs, the default available levels are:
logging.NOTSET = 0 logging.DEBUG = 10 logging.INFO = 20 logging.WARNING = 30 logging.ERROR = 40 logging.CRITICAL = 50
show_function – Whether you want the function name that is being logged from to show up in the info.
custom_levels – Please note that this is global. If you define it for one logger, it exists for all loggers. Those loggers may not be set up to use it by default, though.