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.

Logging Cookbook: Creating a lot of loggers

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

__init__(name, filename, level, log_dir)[source]#

Initialize self. See help(type(self)) for accurate signature.

delete()[source]#

Delete the mock logger from memory.

exception(msg, *args, exc_info=True, **kwargs)[source]#

Log a message with severity ‘ERROR’ on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format.

Logging.getLogger(name)[source]#
Logging.__init__(config)[source]#

Initialize self. See help(type(self)) for accurate signature.

logging.getLogger(name=None)[source]#

Return a logger with the specified name, creating it if necessary.

If no name is specified, return the root logger.