Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/docs/groups/logging.md is written in an unsupported language. File is not indexed.

0001 @defgroup logging Logging
0002 @brief Subsystem for logging and message handling
0003 
0004 The ACTS logging system provides flexible, hierarchical logging with multiple
0005 severity levels and decorators. Logger objects can easily be created using the
0006 @ref Acts::getDefaultLogger function which should be sufficient to get you
0007 started. In case you need more customized debug output, you can make use of the
0008 output decorators defined in `Acts::Logging` or even write your own
0009 implementation of @ref Acts::Logging::OutputDecorator.
0010 
0011 ## Logging Levels
0012 
0013 The logging system supports the following severity levels (from lowest to highest):
0014 
0015 - [`VERBOSE`](@ref Acts::Logging::VERBOSE): @copybrief Acts::Logging::VERBOSE
0016 - [`DEBUG`](@ref Acts::Logging::DEBUG): @copybrief Acts::Logging::DEBUG
0017 - [`INFO`](@ref Acts::Logging::INFO): @copybrief Acts::Logging::INFO
0018 - [`WARNING`](@ref Acts::Logging::WARNING): @copybrief Acts::Logging::WARNING
0019 - [`ERROR`](@ref Acts::Logging::ERROR): @copybrief Acts::Logging::ERROR
0020 - [`FATAL`](@ref Acts::Logging::FATAL): @copybrief Acts::Logging::FATAL
0021 
0022 ## Using Logging Macros
0023 
0024 @copydetails logging_macros
0025 
0026 ## Logging Patterns {#logging_patterns}
0027 
0028 ACTS provides several patterns for integrating logging into your code, each
0029 suited for different use cases.
0030 
0031 ### Member Logger Pattern
0032 
0033 Use this pattern when a class needs persistent logging throughout its lifetime.
0034 The logger is stored as a member variable and passed to the constructor.
0035 
0036 **Best for:**
0037 
0038 - Classes that perform ongoing work with logging needs
0039 - Components that need consistent logger identity
0040 - Objects with well-defined lifetimes
0041 - Allowing caller to control logging configuration
0042 
0043 @snippet{trimleft} examples/logging.cpp Member Logger Pattern
0044 
0045 **Key characteristics:**
0046 
0047 - Logger stored as `std::unique_ptr<const Acts::Logger>`
0048 - Provides `logger()` accessor method returning const reference
0049 - Constructor accepts `std::unique_ptr<const Acts::Logger>` by value and moves it
0050 - Caller creates logger with `getDefaultLogger()` or other logger factory
0051 - ACTS logging macros work directly in member functions
0052 - Ownership transferred to the class instance
0053 
0054 ### Const Reference Argument Pattern
0055 
0056 Use this pattern when a function or algorithm should accept a logger from the
0057 caller, providing maximum flexibility.
0058 
0059 **Best for:**
0060 
0061 - Standalone functions and algorithms
0062 - Places where it's inconvenient to store a member logger
0063 
0064 @snippet{trimleft} examples/logging.cpp Const Ref Argument Pattern
0065 
0066 **Key characteristics:**
0067 
0068 - Logger passed as `const Acts::Logger&` parameter
0069 - Often has default value using `getDummyLogger()`
0070 - Allows caller to choose logging behavior
0071 - Supports dependency injection for testing
0072 
0073 ### `getDummyLogger` Pattern
0074 
0075 Use this pattern when logging is optional or should be disabled by default. In
0076 contract to @ref getDefaultLogger, this function returns a logger that discards
0077 all messages, resulting in negligible runtime overhead. It is useful in cases
0078 where you don't want to default to logging to `std::cout`, but not all
0079 call-sites give you easy access to a logger.
0080 
0081 **Best for:**
0082 
0083 - Optional logging that can be enabled when debugging
0084 - Functions where most callers don't have a logger
0085 
0086 @snippet{trimleft} examples/logging.cpp getDummyLogger Pattern
0087 
0088 **Key characteristics:**
0089 
0090 - Returns a global dummy logger that discards all output
0091 - negligible runtime overhead when used (messages not processed)
0092 - Common default for function parameters
0093 - Can be overridden with real logger when needed
0094 
0095 ### `getDefaultLogger` Factory Function
0096 
0097 Use this function to create standalone loggers with standard formatting
0098 (timestamp, component name, log level). Note that the loggers returned by this
0099 function will always look to standard output streams (e.g. `std::cout`).
0100 
0101 ## Advanced Topics
0102 
0103 ### Custom Output Streams
0104 
0105 @ref Acts::getDefaultLogger accepts an optional output stream parameter:
0106 
0107 @snippet{trimleft} examples/logging.cpp Custom Output Streams
0108 
0109 ### Logger Cloning
0110 
0111 Loggers can be cloned to create independent instances with optional
0112 modifications to the name and/or log level. This is particularly useful when
0113 creating sub-component loggers or when you need multiple loggers with similar
0114 configurations.
0115 
0116 @snippet{trimleft} examples/logging.cpp Logger Cloning
0117 
0118 #### Common Use Cases
0119 
0120 **Sub-component loggers:** When a class has multiple internal components that need separate logging:
0121 
0122 @snippet{trimleft} examples/logging.cpp Logger Cloning Sub-component
0123 
0124 **Per-component log levels:** When building detectors or systems with different verbosity needs:
0125 
0126 @snippet{trimleft} examples/logging.cpp Logger Cloning Per-component Levels
0127 
0128 **Testing:** Creating test loggers with specific configurations:
0129 
0130 @snippet{trimleft} examples/logging.cpp Logger Cloning Testing
0131 
0132 ## Logger Integration
0133 
0134 In case you are using ACTS in another framework which comes with its own
0135 logging facility (e.g. Gaudi) you can pipe the logging output from ACTS
0136 tools and algorithms to your framework's logging system by supplying different
0137 implementations of:
0138 
0139 - @ref Acts::Logging::OutputFilterPolicy (for mapping logging levels)
0140 - @ref Acts::Logging::OutputPrintPolicy (for passing the Acts output
0141   to your internal logging system)
0142 
0143 There are two approaches to logger integration:
0144 
0145 1. **Overriding [`getDefaultLogger`](@ref Acts::getDefaultLogger)** (now **discouraged**).
0146    This has the downside that log levels cannot be controlled from top-level
0147    experiment specific code. This means that it is non-trivial to steer the log
0148    level of an e.g. Gaudi algorithm via the `OutputLevel` property, and have
0149    the ACTS code respect this log level.
0150 
0151    @warning ACTS code has iteratively moved to not construct loggers via
0152    @ref Acts::getDefaultLogger as much as possible, in favor of using a
0153    const-reference to @ref Acts::Logger. The latter can be defaulted to a
0154    dummy logger using @ref Acts::getDummyLogger. It is more suitable to
0155    pass into functions that might be called from other ACTS functions (rather
0156    than constructing a local logger via `getDefaultLogger`, or creating logger
0157    instances on the fly).
0158 
0159    Since ACTS makes extensive use of @ref Acts::getDefaultLogger to provide
0160    sufficient information for debugging, you might want to provide a modified
0161    implementation of this function (using your output filter and printing
0162    policies) to also pipe this output to your framework. You can use the
0163    `LD_PRELOAD` approach by providing an appropriate implementation for a
0164    function of the following signature into a separate source file and compile
0165    it in a shared library:
0166 
0167    @snippet{trimleft} examples/logging.cpp Logger preload
0168 
0169    Then you can run your executable with:
0170 
0171    ```console
0172    LD_PRELOAD=<YOUR_SHARED_LIBRARY> path/to/your/executable
0173    ```
0174 
0175 2. **Passing logger instances to high level components** (recommended), and rely on ACTS code to
0176    pass them into lower level classes / functions. This is the preferred approach
0177    as it allows proper control of log levels from top-level experiment code.
0178 
0179 ## Logging Thresholds
0180 
0181 @copydetails logging_thresholds
0182 
0183 Two main functions exist to interact with the failure threshold:
0184 
0185 - @ref Acts::Logging::getFailureThreshold
0186 - @ref Acts::Logging::setFailureThreshold