woodglue.log_setup¶
Logging setup for wgl start: journal, rotated file, or a logging: dictConfig.
Logging setup for wgl start.
Woodglue configures the root logger itself from woodglue.yaml; lythonic only
contributes NodeRunLogFilter, which adds run_id and node_label to records
logged inside a node run.
Default behavior¶
Under systemd (detected by JOURNAL_STREAM in the environment), records go to
stderr without a timestamp, since the journal adds its own. Every line carries an
sd-daemon priority prefix (<7> DEBUG, <6> INFO, <4> WARNING, <3> ERROR,
<2> CRITICAL) so journald records the right priority. No file log is written
unless storage.log_file is set explicitly.
Outside systemd, records go to <data>/wgl.log (or storage.log_file).
Every file log is a RotatingFileHandler, rotated at storage.log_max_bytes
(default 10 MB) keeping storage.log_backup_count backups (default 5).
storage:
log_file: logs/wgl.log # relative to the data dir; null disables the file log
log_level: INFO # root level, INFO when unset
log_max_bytes: 10485760
log_backup_count: 5
loggers: # per-logger levels
tornado.access: WARNING
With log_file: null outside systemd, records go to stderr with a timestamp so
they are not lost. An unknown level name in log_level or loggers stops
wgl start with a ValueError rather than silently falling back to DEBUG.
Custom setup with logging:¶
A top-level logging: section in woodglue.yaml is passed to
logging.config.dictConfig and replaces everything above, including the
storage.log_* settings. Attach NodeRunLogFilter to keep the run context:
logging:
version: 1
disable_existing_loggers: false
filters:
noderun:
(): lythonic.compose.log_context.NodeRunLogFilter
formatters:
plain:
format: "%(asctime)s %(levelname)s [%(name)s] run=%(run_id)s %(message)s"
handlers:
console:
class: logging.StreamHandler
formatter: plain
filters: [noderun]
root:
level: INFO
handlers: [console]
Keep disable_existing_loggers: false: the dictConfig default of true
silences every logger created before setup, including woodglue's own.
JournalFormatter
¶
Bases: Formatter
Prefix every output line with the sd-daemon priority of the record's level.
journald reads the prefix per line, so the continuation lines of a traceback keep the record's priority instead of defaulting to INFO.
Source code in src/woodglue/log_setup.py
setup_logging(config, env=None)
¶
Configure the root logger for wgl start and return a one-line description
of what is in effect, e.g. Logging to journal.
Expects config.storage already resolved against the data dir. Safe to call
repeatedly: handlers from a previous call are replaced, not duplicated.
env defaults to os.environ.