fractal_server.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:¶
_load_logging_config(config_env)
¶
Load logging configuration from a YAML file path.
On success sets _CONFIG_LOADED = True.
Source code in fractal_server/logger/__init__.py
close_logger(logger)
¶
Close all handlers associated to a logging.Logger object
| PARAMETER | DESCRIPTION |
|---|---|
|
The actual logger
TYPE:
|
Source code in fractal_server/logger/__init__.py
config_uvicorn_loggers()
¶
Change the formatter for the uvicorn access/error loggers.
Skipped when an external logging config file is loaded, since that file already configures the uvicorn 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/__init__.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/__init__.py
reset_logger_handlers(logger)
¶
Close and remove all handlers associated to a logging.Logger object
| PARAMETER | DESCRIPTION |
|---|---|
|
The actual logger
TYPE:
|
Source code in fractal_server/logger/__init__.py
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.
Note on external logging config (LOG_CONFIG_FILE):
When an external config is loaded (_CONFIG_LOADED is True),
the StreamHandler setup is always skipped (the external config owns the
logging hierarchy). However, if log_file_path is provided, the
FileHandler is still added unconditionally. This is because certain
log files (e.g. workflow.log, task-collection logs) are functional
artifacts that are read back into the database — they must always be
written regardless of how application logging is configured.
| 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:
|