MMLogger — mmengine 0.10.7 documentation (original) (raw)

class mmengine.logging.MMLogger(name, logger_name='mmengine', log_file=None, log_level='INFO', file_mode='w', distributed=False, file_handler_cfg=None)[source]

Formatted logger used to record messages.

MMLogger can create formatted logger to log message with different log levels and get instance in the same way as ManagerMixin.MMLogger has the following features:

Note

Examples

logger = MMLogger.get_instance(name='MMLogger', logger_name='Logger')

Although logger has name attribute just like logging.Logger

We cannot get logger instance by logging.getLogger.

assert logger.name == 'Logger' assert logger.instance_name = 'MMLogger' assert id(logger) != id(logging.getLogger('Logger'))

Get logger that do not store logs.

logger1 = MMLogger.get_instance('logger1')

Get logger only save rank0 logs.

logger2 = MMLogger.get_instance('logger2', log_file='out.log')

Get logger only save multiple ranks logs.

logger3 = MMLogger.get_instance('logger3', log_file='out.log', distributed=True)

Parameters:

callHandlers(record)[source]

Pass a record to all relevant handlers.

Override callHandlers method in logging.Logger to avoid multiple warning messages in DDP mode. Loop through all handlers of the logger instance and its parents in the logger hierarchy. If no handler was found, the record will not be output.

Parameters:

record (LogRecord) – A LogRecord instance contains logged message.

Return type:

None

classmethod get_current_instance()[source]

Get latest created MMLogger instance.

MMLogger can call get_current_instance() before any instance has been created, and return a logger with the instance name “mmengine”.

Returns:

Configured logger instance.

Return type:

MMLogger

setLevel(level)[source]

Set the logging level of this logger.

If logging.Logger.selLevel is called, all logging.Loggerinstances managed by logging.Manager will clear the cache. SinceMMLogger is not managed by logging.Manager anymore,MMLogger should override this method to clear caches of allMMLogger instance which is managed by ManagerMixin.

level must be an int or a str.