idmtools.core.logging module

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.

idmtools.core.logging.setup_logging(level: Union[int, str] = 30, log_filename: str = 'idmtools.log', console: Union[str, 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.

  • log_filename – Name of file to log messages to.

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

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, log_filename, console: bool = False)
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