Logging#
Most C-PAC logging is handled by the built-in Python logging
library. When logging, take care to choose an appropriate getLogger
function or method. While CPAC.utils.monitoring.custom_logging.getLogger
and nipype.utils.logger.Logging.getLogger
each fall back on logging.getLogger
,
each have their own intended use cases.
Loggers are singletons that are never freed during a script execution, and so creating lots of loggers will use up memory which can’t then be freed.
CPAC.utils.monitoring.custom_logging.getLogger
will look for a CPAC.utils.monitoring.custom_logging.MockLogger
before falling back on logging.getLogger
.
A CPAC.utils.monitoring.custom_logging.MockLogger
can be used in place of a logging.Logger
and deleted from memory when no longer needed. For an example, see how missing_log
is created and deleted in CPAC.pipeline.check_outputs.check_outputs
.
nipype.utils.logger.Logging.getLogger
will only consider loggers that are part of the class instance calling the method.
- CPAC.utils.monitoring.custom_logging.getLogger(name)[source]#
Function to get a mock logger if one exists, falling back on real loggers.
- Parameters
- namestr
- Returns
- loggerCPAC.utils.monitoring.custom_logging.MockLogger or logging.Logger
- class CPAC.utils.monitoring.custom_logging.MockLogger(name, filename, level, log_dir)[source]#
Mock logging.Logger to provide the same API without keeping the logger in memory.
Methods
delete
()Delete the mock logger from memory.
exception
(msg, *args[, exc_info])Log a message with severity ‘ERROR’ on the root logger, with exception information.
critical
debug
error
info
warning