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

critical()

Log a message if logging level >= critical.

debug()

Log a message if logging level >= debug.

delete()

Delete the mock logger from memory.

error()

Log a message if logging level >= error.

info()

Log a message if logging level >= info.

warning()

Log a message if logging level >= warning.

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

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

critical()

Log a message if logging level >= critical. See Logging Levels for a list of levels.

debug()

Log a message if logging level >= debug. See Logging Levels for a list of levels.

delete()[source]

Delete the mock logger from memory.

error()

Log a message if logging level >= error. See Logging Levels for a list of levels.

info()

Log a message if logging level >= info. See Logging Levels for a list of levels.

warning()

Log a message if logging level >= warning. See Logging Levels for a list of levels.

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.