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:
- 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:
- 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:
- 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:
- 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:
- 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.
- 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: