Logging¶
The logging observer adds request-specific metadata to log lines coming out of your application.
Changed in version 1.4: Logs are now formatted as JSON objects.
Configuration¶
No configuration is necessary, this observer is always enabled when you call
configure_observers().
If your application is run with baseplate-serve, logging can be controlled with Python’s standard logging configuration. See Logging for more information.
Outputs¶
The baseplate-serve command will automatically set up log formatting.
When directly used from a TTY, a simplified human-readable message format is emitted. Only the level and message are included.
In production usage, log entries are formatted as JSON objects that can be parsed automatically by log analysis systems. Log entry objects contain the following keys:
messageThe message.
levelThe name of the log level at which the log entry was generated, e.g.
INFO,WARNING, etc.Along with
name, this can be useful for configuring logging to squelch noisy messages.nameThe name of the
Loggerused.Along with
level, this can be useful for configuring logging to squelch noisy messages.traceIDThe Trace ID of the request within context of which the log entry was generated. This can be used to correlate log entries from the same root request within and across services.
Only present if the log entry was generated during a request. Otherwise see
thread.pathnameThe path to the Python source for the module that generated the log entry.
moduleThe name of the module in which the log entry was generated.
funcNameThe name of the function that generated the log entry.
linenoThe line number on which the log entry was generated.
processThe OS-level Process ID of the process that generated the log entry.
processNameThe name of the process that generated the log entry (as set on
multiprocessing.current_process().name).threadThe name of the thread that generated the log entry (as set on
threading.current_thread().name).This may be absent if the log entry was generated from within processing of a request, in which case
traceIDwill be included instead.
Older logging¶
Before v1.4, log entries were written in a custom format:
17905:7296338476964580186:baseplate.lib.metrics:DEBUG:Blah blah
^ ^ ^ ^ ^
| | | | Log message
| | | Log level
| | Name of the logger
| Trace ID of the request
Process ID
Direct Use¶
Any log messages emitted with the Python standard logging interfaces
will be annotated by this observer.