...
Each process wishing to log must import the following modules:
The
logger
class withfrom modules.logger import logger
Import the built in
inspect
module withimport inspect
Create a logger in the __init__
function for a module (TODO: determine where to create the logger in main) with self.__create_logger_result, custom logger module in common:
Logger creation should be done in the create method of a module:
Code Block |
---|
result, self.__logger = logger.logger.create("name" |
...
, True)
if not result:
return False, None |
Replace “name” with the desired name of the logger - this will also be the name of the log_file. It is suggested to name the logger after the process doing the logging. We don’t want to take down a process if logger creation fails, so we won’t handle the failed case, but we will only log if the result is True
The second argument is a boolean indicating if we should log to a file.
The logger supports the five default logging levels, in increasing order of severity: debug
, info
, warning
, error
, critical
.
The logger takes a 2 inputs: the log message and the frame as input. The frame is an object from the inspect
module, containing information about the current whether or not to include frame information. Frame information is metadata about the code being run - of which we use extract the linefile, function, and fileline of the code.
To log a message, use the following template, replace debug
with the desired loggerlog level:
Code Block |
---|
if self.__create_logger_result: frame = inspect.currentframe() self._logger.debug("log message", frameTrue) |
Design Choice
There are several challenges with multiprocessing logging:
...