File: TECH_NOTE.md

package info (click to toggle)
python-logistro 2.0.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 204 kB
  • sloc: python: 350; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 957 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Technical Note

Python's `logging` is over-engineered and not quite good enough:

## Background

`Loggers` exist in a tree structure, hierarchy defined by the name.
There is a root logger that you cannot change.
`Loggers` have `Handlers`, `Handlers` have `Formatters`. When you call a logging
function on a `Logger`, it searches up the tree for all parent handlers.
In simple usage, usually only the root logger has a handler.

## Problem

* Changing the format mid-program means finding all the (relevant?) handlers
in the tree. `pytest` for example attaches other handlers so it can capture
logging. Our `better_config()` will set our format on the root logger's
handlers.

* You cannot attach two formatters to a handler
* Two handlers cannot access the same file

Having both those be true simultaneously presents problems.

For our process logger, where a lot of context is erroneous,
we strip useless data from the process logger by using a filter.