trlcdoc.log
Console output of trlcdoc: logging setup, verbosity levels and redaction of secrets.
All trlcdoc modules log with logging.getLogger(__name__), below the ‘trlcdoc’ logger configured here. INFO is the default output, DEBUG (-v) adds decisions and tool details, TRACE (-vv) adds per-item details.
Attributes
Classes
Write INFO and below to stdout, WARNING and above to stderr. |
|
Format a message unchanged, and prefix debug and trace messages with their level name. |
Functions
|
Configure the trlcdoc logger for the console. |
|
Replace the user and password of a URL, e.g. of a PlantUML server. |
|
Replace the secrets of environment variables. |
|
Format a command so it can be pasted into a shell of the system. |
Module Contents
- trlcdoc.log.TRACE = 5
- trlcdoc.log.LOGGER_NAME = 'trlcdoc'
- trlcdoc.log.VERBOSITY_LEVELS
- trlcdoc.log.SECRET_NAME
- trlcdoc.log.REDACTED = '***'
- class trlcdoc.log.ConsoleHandler(level=NOTSET)[source]
Bases:
logging.Handler
Write INFO and below to stdout, WARNING and above to stderr.
The stream is looked up for every message instead of once, so output redirected later, e.g. by pytest, receives the messages. Every message is flushed, so it appears before the output of a tool started next.
- class trlcdoc.log.LevelFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
logging.Formatter
Format a message unchanged, and prefix debug and trace messages with their level name.
The default output keeps its plain text, the verbose lines are recognizable.
- trlcdoc.log.setup_logging(verbosity: int = 0) None[source]
Configure the trlcdoc logger for the console.
It can be called again, e.g. for each run in the tests: the handler is replaced, not added.
- Parameters:
verbosity (int) – Number of -v options: 0 for the default output, 1 for DEBUG, 2 or more for TRACE.
- trlcdoc.log.redact_url(text: str) str[source]
Replace the user and password of a URL, e.g. of a PlantUML server.
- Parameters:
text (str) – A URL or any other text.
- Returns:
The text, with
***instead of the user info if it is a URL with one.- Return type:
str