logger
This module provides logging utilities
close_logger(logger)
¶
Close all handlers associated to a logging.Logger
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
The actual logger |
required |
Source code in fractal_server/logger.py
117 118 119 120 121 122 123 124 125 |
|
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
gunicorn
startup command, with--access-logfile
and--error-logfile
options 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
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
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)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger_name |
Optional[str]
|
Name of logger |
None
|
Returns:
Logger with name logger_name
Source code in fractal_server/logger.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
reset_logger_handlers(logger)
¶
Close and remove all handlers associated to a logging.Logger
object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger |
Logger
|
The actual logger |
required |
Source code in fractal_server/logger.py
128 129 130 131 132 133 134 135 136 |
|
set_logger(logger_name, *, log_file_path=None)
¶
Set up a fractal-server
logger
The logger (a logging.Logger
object) will have the following properties:
- The attribute
Logger.propagate
set toFalse
; - One and only one
logging.StreamHandler
handler, with severity level set toFRACTAL_LOGGING_LEVEL
and formatter set as in thelogger.LOG_FORMAT
variable from the current module; - One or many
logging.FileHandler
handlers, including one pointint tolog_file_path
(if set); all these handlers have severity level set tologging.DEBUG
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logger_name |
str
|
The identifier of the logger. |
required |
log_file_path |
Optional[Union[str, Path]]
|
Path to the log file. |
None
|
Returns:
Name | Type | Description |
---|---|---|
logger |
Logger
|
The logger, as configured by the arguments. |
Source code in fractal_server/logger.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|