idmtools.core.logging module

class idmtools.core.logging.SafeRotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=False)

Bases: logging.handlers.RotatingFileHandler

doRollover() → None

Do a rollover, as described in __init__().

class idmtools.core.logging.IDMQueueListener(queue, *handlers, respect_handler_level=False)

Bases: logging.handlers.QueueListener

dequeue(block)

Dequeue a record and return it, optionally blocking.

The base implementation uses get. You may want to override this method if you want to use timeouts or work with custom queue implementations.

class idmtools.core.logging.IDMQueueHandler(queue)

Bases: logging.handlers.QueueHandler

prepare(record)

Prepares a record for queuing. The object returned by this method is enqueued.

The base implementation formats the record to merge the message and arguments, and removes unpickleable items from the record in-place.

You might want to override this method if you want to convert the record to a dict or JSON string, or send a modified copy of the record while leaving the original intact.

class idmtools.core.logging.PrintHandler(level=0)

Bases: logging.Handler

handle(record: logging.LogRecord) → None

Conditionally emit the specified logging record.

Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission.

idmtools.core.logging.setup_logging(level: Union[int, str] = 30, filename: str = 'idmtools.log', console: Union[str, bool] = False, file_level: str = 'DEBUG', force: bool = False) → logging.handlers.QueueListener

Set up logging.

Parameters
  • level – Log level. Default to warning. This should be either a string that matches a log level from logging or an int that represent that level.

  • filename – Name of file to log messages to. If set to empty string, file logging is disabled

  • console – When set to True or the strings “1”, “y”, “yes”, or “on”, console logging will be enabled.

  • file_level – Level for logging in file

  • force – Force setup, even if we have done it once

Returns

Returns the QueueListener created that writes the log messages. In advanced scenarios with multi-processing, you may need to manually stop the logger.

idmtools.core.logging.setup_handlers(level: int, filename, console: bool = False, file_level: int = None)

Setup Handlers for Global and user Loggers

Parameters
  • level – Level for the common logger

  • filename – Log filename. Set to “” to disable file based logging

  • console – Enable console based logging only

  • file_level – File Level logging

Returns

FileHandler or None

idmtools.core.logging.setup_user_logger(console: bool)

Setup the user logger. This logger is meant for user output only

Parameters

console – Is Console enabled. If so, we don’t install a user loger

Returns:

idmtools.core.logging.set_file_logging(file_level: int, formatter: logging.Formatter, filename: str)

Set File Logging

Parameters
  • file_level – File Level

  • formatter – Formatter

  • filename – Log Filename

Returns

Return File handler

idmtools.core.logging.create_file_handler(file_level, formatter, filename)
idmtools.core.logging.reset_logging_handlers()
idmtools.core.logging.exclude_logging_classes(items_to_exclude=None)
idmtools.core.logging.register_stop_logger_signal_handler(listener) → NoReturn

Register a signal watcher that will stop our logging gracefully in the case of queue based logging.

Parameters

listener – The log listener object.

Returns

None