trlcdoc.log =========== .. py:module:: trlcdoc.log .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: trlcdoc.log.TRACE trlcdoc.log.LOGGER_NAME trlcdoc.log.VERBOSITY_LEVELS trlcdoc.log.SECRET_NAME trlcdoc.log.REDACTED Classes ------- .. autoapisummary:: trlcdoc.log.ConsoleHandler trlcdoc.log.LevelFormatter Functions --------- .. autoapisummary:: trlcdoc.log.setup_logging trlcdoc.log.redact_url trlcdoc.log.redact_env trlcdoc.log.command_line Module Contents --------------- .. py:data:: TRACE :value: 5 .. py:data:: LOGGER_NAME :value: 'trlcdoc' .. py:data:: VERBOSITY_LEVELS .. py:data:: SECRET_NAME .. py:data:: REDACTED :value: '***' .. py:class:: ConsoleHandler(level=NOTSET) Bases: :py:obj:`logging.Handler` .. autoapi-inheritance-diagram:: trlcdoc.log.ConsoleHandler :parts: 1 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. .. py:method:: emit(record: logging.LogRecord) -> None Write a message to its stream. :param record: The message. :type record: logging.LogRecord .. py:class:: LevelFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None) Bases: :py:obj:`logging.Formatter` .. autoapi-inheritance-diagram:: trlcdoc.log.LevelFormatter :parts: 1 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. .. py:method:: format(record: logging.LogRecord) -> str Format a message. :param record: The message. :type record: logging.LogRecord :returns: The message, with 'DEBUG: ' or 'TRACE: ' in front for verbose messages. :rtype: str .. py:function:: setup_logging(verbosity: int = 0) -> None 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. :param verbosity: Number of -v options: 0 for the default output, 1 for DEBUG, 2 or more for TRACE. :type verbosity: int .. py:function:: redact_url(text: str) -> str Replace the user and password of a URL, e.g. of a PlantUML server. :param text: A URL or any other text. :type text: str :returns: The text, with ``***`` instead of the user info if it is a URL with one. :rtype: str .. py:function:: redact_env(env: dict[str, str]) -> dict[str, str] Replace the secrets of environment variables. :param env: Environment variables. :type env: dict[str, str] :returns: A copy with ``***`` as value of variables named like a secret, and URLs without user info. :rtype: dict[str, str] .. py:function:: command_line(cmd: list[str]) -> str Format a command so it can be pasted into a shell of the system. :param cmd: Command and its arguments. :type cmd: list[str] :returns: The command line, quoted for cmd.exe on Windows and for a POSIX shell elsewhere. :rtype: str