cicada.logging module

Functionality to make logging from multiple processes easier.

class cicada.logging.Logger(logger, communicator, sync=True)[source]

Bases: object

Wrap a normal Python logger with a Cicada communicator to synchronize player output.

Note

Because Logger communicates among players for synchronization, it can have a significant effect on performance, even when log messages are discarded by log levels or other filtering.

Furthermore, Logger should not be used in error recovery code, since it will fail attempting to communicate with players that are (presumably) dead.

You can pass sync=False when creating Logger to disable synchronization, e.g. if you’re running your code on separate hosts or in separate terminal sessions.

Parameters:
  • logger (logging.Logger, required.) – The Python logger to be used for output.

  • communicator (cicada.communicator.interface.Communicator, required) – The communicator that will be used to synchronize output among players.

  • sync (bool, optional) – Used to control synchronization, which is enabled by default.

property communicator

Returns the underlying communicator.

critical(msg, *args, src=None, **kwargs)[source]

Log a critical message, synchronized among players.

Note

This is a collective operation that must be called by all players that are members of the communicator.

The arguments match those of logging.Logger.critical(), with the addition of the following:

Parameters:

src (int or sequence of int, optional) – If specified, only the given player(s) will produce log output.

debug(msg, *args, src=None, **kwargs)[source]

Log a debug message, synchronized among players.

Note

This is a collective operation that must be called by all players that are members of the communicator.

The arguments match those of logging.Logger.debug(), with the addition of the following:

Parameters:

src (int or sequence of int, optional) – If specified, only the given player(s) will produce log output.

error(msg, *args, src=None, **kwargs)[source]

Log an error message, synchronized among players.

Note

This is a collective operation that must be called by all players that are members of the communicator.

The arguments match those of logging.Logger.error(), with the addition of the following:

Parameters:

src (int or sequence of int, optional) – If specified, only the given player(s) will produce log output.

info(msg, *args, src=None, **kwargs)[source]

Log an info message, synchronized among players.

Note

This is a collective operation that must be called by all players that are members of the communicator.

The arguments match those of logging.Logger.info(), with the addition of the following:

Parameters:

src (int or sequence of int, optional) – If specified, only the given player(s) will produce log output.

log(level, msg, *args, src=None, **kwargs)[source]

Log a message, synchronized among players.

Note

This is a collective operation that must be called by all players that are members of the communicator.

The arguments match those of logging.Logger.log(), with the addition of the following:

Parameters:

src (int or sequence of int, optional) – If specified, only the given player(s) will produce log output.

property logger

Returns the underlying Python logging.Logger.

override(*, sync=None)[source]

Temporarily change logging behavior.

Use override() to temporarily modify logger behavior in a with statement:

with log.override(sync=False):
    # Do uncoordinated logging here.
# Go back to coordinated logging here.

Note

Changes to logging behavior must be consistent for all players that are members of the communicator.

Parameters:

sync (bool, optional) – If specified, override the logger sync property.

Returns:

context – A context manager object that will restore the loger state when exited.

Return type:

object

property sync

Controls whether coordinated logging is enabled or not.

Note

Changes to sync must be consistent for all players that are members of the communicator.

warning(msg, *args, src=None, **kwargs)[source]

Log a warning message, synchronized among players.

Note

This is a collective operation that must be called by all players that are members of the communicator.

The arguments match those of logging.Logger.warning(), with the addition of the following:

Parameters:

src (int or sequence of int, optional) – If specified, only the given player(s) will produce log output.