Logger
This module provides logging utilities
| FUNCTION | DESCRIPTION |
|---|---|
close_logger |
Close all handlers associated to a |
config_uvicorn_loggers |
Change the formatter for the uvicorn access/error loggers. |
get_logger |
Wrap the |
reset_logger_handlers |
Close and remove all handlers associated to a |
set_logger |
Set up a |
Attributes¶
Functions:¶
close_logger(logger)
¶
config_uvicorn_loggers()
¶
Change the formatter for the uvicorn access/error loggers.
This is similar to https://stackoverflow.com/a/68864979/19085332. See also https://github.com/tiangolo/fastapi/issues/1508.
This function is meant to work in two scenarios:
- The most relevant case is for a
gunicornstartup command, with--access-logfileand--error-logfileoptions set. - The case of
fractalctl start(directly callinguvicorn).
Because of the second use case, we need to check whether uvicorn loggers already have a handler. If not, we skip the formatting.
Source code in fractal_server/logger.py
get_logger(logger_name=None)
¶
Wrap the
logging.getLogger
function.
The typical use case for this function is to retrieve a logger that was already defined, as in the following example:
def function1(logger_name):
logger = get_logger(logger_name)
logger.info("Info from function1")
def funtion2():
logger_name = "my_logger"
logger = set_logger(logger_name)
logger.info("Info from function2")
function1(logger_name)
close_logger(logger)
| PARAMETER | DESCRIPTION |
|---|---|
|
Name of logger
TYPE:
|
Returns:
Logger with name logger_name
Source code in fractal_server/logger.py
reset_logger_handlers(logger)
¶
set_logger(logger_name, *, log_file_path=None, default_logging_level=None)
¶
Set up a fractal-server logger
The logger (a logging.Logger object) will have the following properties:
- The attribute
Logger.propagateset toFalse; - One and only one
logging.StreamHandlerhandler, with severity level set toFRACTAL_LOGGING_LEVEL(ordefault_logging_level, if set), and formatter set as in thelogger.LOG_FORMATvariable from the current module; - One or many
logging.FileHandlerhandlers, including one pointint tolog_file_path(if set); all these handlers have severity level set tologging.DEBUG.
| PARAMETER | DESCRIPTION |
|---|---|
|
The identifier of the logger.
TYPE:
|
|
Path to the log file. |
|
Override for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
logger
|
The logger, as configured by the arguments.
TYPE:
|