petri.loggin module

Configure a single logger.

class petri.loggin.LogDest[source]

Bases: enum.Enum

Define allowed destinations for logs.

CONSOLE = 'CONSOLE'

Log to console

FILE = 'FILE'

Log to file

class petri.loggin.LogFormatter[source]

Bases: enum.Enum

Define allowed destinations for logs.

COLOR = 'COLOR'

pprinted, colored, for humans

JSON = 'JSON'

JSONs, eg for filebeat or similar, for machines

class petri.loggin.LogLevel[source]

Bases: enum.IntEnum

Explicitly define allowed logging levels.

CRITICAL = 50
DEBUG = 10
ERROR = 40
INFO = 20
NOTSET = 0
TRACE = 1
WARNING = 30
petri.loggin.configure_logging(name, level, dest, formatter, log_file, kidnap_loggers=False)[source]

Setup logging with (hopefully) sane defaults.

Parameters:
  • name – Name for the logger.
  • level (LogLevel) – Level from where to start logging.
  • dest (LogDest) – Whether to log to file or console.
  • formatter (LogFormatter) – Whether to output data as json or colored, parsed logs.
  • log_file (Path) – Where to store logfiles. Only used if dest='FILE'.
  • kidnap_loggers – Whether to configure the loggers on just instantiate one.
Returns:

The configured logger.

petri.loggin.maybe_patch_tqdm(logger, dev_mode)[source]

Replaces tqdm.tqdm calls with noops.

petri.loggin.trace_using(logger)[source]

Decorator factory to trace callables.

Parameters:logger – The logger to use for tracing
Returns:The decorator, which takes a function and decorates it.