Skip to content

Logging

Emir Muhammad edited this page Jan 12, 2026 · 6 revisions

Drunc leverages the native python logging functionality. The repository daqpytools includes several useful functions and wrappers to the Python's logging module. The philosophy and use of loggers for drunc is described below.

Structure and naming convention

A pseudo-root logger called drunc is defined with no handlers attached, and all loggers used within drunc are descendents of the drunc logger. Each subsequent child logger is referenced by the class names as drunc.X, drunc.X.Y, and so forth.

The loggers can be broadly grouped by the parent loggers, such as drunc.process_manager.x and drunc.controller.y. The full naming convention is

<process_manager/process_manager_shell/controller/controller_shell/unified_shell/utils>.<subcategory>

for which subcategory is a parameter which can be freely named typically by the class that uses the given logger.

The parent handlers are primarily where handlers are initialised and defined. Through inheritance, further descendants will inheret the loggers of the parent, so that they can be shared and repeated code can be minimised.

inheritance

Core handlers

The logging handlers control the formatting behaviour of the log records, and transmit them to the desired outputs. There are three primary sets of core handlers that exist within drunc, these being RichHandler, StreamHandler, and FileHandler. The RichHandler is meant for redirecting the log records to the terminal output with Rich formatting and are not expected to be saved to an output file. The StreamHandler is for messages that are sent to the terminal without any Rich formatting and are meant for everything that gets kept in the logs via a bash redirect to an log file. The FileHandler is a native handler that automatically redirects the log messages to a specified file.

Each logger has either a RichHandler for viewing terminal output which will not be kept in the logs, or a StreamHandler for everything that gets kept in the logs. The controllers are split into two further subcategories. The core controller.core primarily has the StreamHandler output which dumps all the logs to stream which gets redirected by the bash output. The interface controller.iface has the RichHandler and serves as the controller 'utilities', and puts the log messages in the terminal with Rich formatting. There is also optional file handling with the FileHandler, but this is only used for the process_manager as the spawned processes have their logs defined when the ouptu is redirected from stdout and stderr to the log file.

handlers

Advanced handlers (WIP as of Dec 2025)

Aside from the core set of loggers and handlers defined natively in drunc, there are several other configurations that interplay with drunc. These can be best thought of as 'streams' which in interact with several other handlers.

streams

The native implementation in drunc is referred to as the 'base' stream and interacts with the three core handlers already discussed. Other streams include the 'Opmon' stream interacting with its own set of handlers, and the 'ERS' stream that interacts with different handlers based on the log message's severity level.

The 'ERS' configuration is configured in OKS (for example here), and are automatically parsed by drunc and daqpytools as they get used.

To deal with the constraints set above, a handler configuration dataclass is constructed to define the relevant configurations and a system of filters is initialised with every handler. When passing a log record that needs to be processed via a specific stream, the log record and the handler configuration is passed to the relevant logger, after which it is processed.

loghandlerstream

The logger passes the two objects to each of filters attached to the handlers, which will only transmit the log message if allowed by the handler configuration.

flowdiagram

Clone this wiki locally