Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1#pragma once
2
3// Load streaming operator from CARL
4#include <carl/io/streamingOperators.h>
5namespace l3pp {
6using carl::operator<<;
7}
8
9#include <l3pp.h>
10
11#include <sstream>
12#include <type_traits>
13
14#if !defined(STORM_LOG_DISABLE_DEBUG) && !defined(STORM_LOG_DISABLE_TRACE)
15#define STORM_LOG_TRACE(message) L3PP_LOG_TRACE(l3pp::Logger::getRootLogger(), message)
16#else
17#define STORM_LOG_TRACE(message) (void)(0)
18#endif
19
20#if !defined(STORM_LOG_DISABLE_DEBUG)
21#define STORM_LOG_DEBUG(message) L3PP_LOG_DEBUG(l3pp::Logger::getRootLogger(), message)
22#else
23#define STORM_LOG_DEBUG(message) (void)(0)
24#endif
25
26// Define STORM_LOG_WARN, STORM_LOG_ERROR and STORM_LOG_INFO to log the given message with the corresponding log levels.
27#define STORM_LOG_INFO(message) L3PP_LOG_INFO(l3pp::Logger::getRootLogger(), message)
28#define STORM_LOG_WARN(message) L3PP_LOG_WARN(l3pp::Logger::getRootLogger(), message)
29#define STORM_LOG_ERROR(message) L3PP_LOG_ERROR(l3pp::Logger::getRootLogger(), message)
30
31namespace storm {
32namespace utility {
33// Named log channels whose level can be toggled independently of the root logger's level.
34constexpr const char* STATISTICS_LOG_CHANNEL = "storm.statistics";
35constexpr const char* PROGRESS_LOG_CHANNEL = "storm.progress";
36} // namespace utility
37} // namespace storm
38
39// STORM_LOG_STATISTICS and STORM_LOG_PROGRESS log at INFO level on their own channel, so their
40// visibility can be enabled/disabled independently of general INFO-level verbosity.
41#define STORM_LOG_STATISTICS(message) L3PP_LOG_INFO(storm::utility::STATISTICS_LOG_CHANNEL, message)
42#define STORM_LOG_PROGRESS(message) L3PP_LOG_INFO(storm::utility::PROGRESS_LOG_CHANNEL, message)
43
44// Runs `callback` and logs the result on `channel` at `level`, but only if that channel would
45// actually emit at that level, avoiding message construction whenever nothing would be printed.
46// `callback` must have signature `bool(std::ostream&)`: write into the stream, then return
47// whether it should be logged.
48//
49// `callback` is taken as a variadic parameter rather than a plain one because it is typically a
50// lambda, and a lambda's capture list ("[a, b, c]") contains top-level commas. The preprocessor
51// only tracks parentheses to decide where macro arguments split, not square or curly brackets, so
52// a plain parameter would misparse such a lambda as multiple arguments; __VA_ARGS__ folds them
53// back into one.
54#define STORM_LOG_LAZY_ON_CHANNEL(channel, level, ...) \
55 do { \
56 auto storm_log_lazy_channel = l3pp::Logger::getLogger(channel); \
57 if (storm_log_lazy_channel->getLevel() <= (level)) { \
58 auto storm_log_lazy_callback = __VA_ARGS__; \
59 static_assert(std::is_invocable_r_v<bool, decltype(storm_log_lazy_callback), std::ostream&>, "callback must have signature bool(std::ostream&)"); \
60 std::ostringstream storm_log_lazy_stream; \
61 if (storm_log_lazy_callback(storm_log_lazy_stream)) { \
62 storm_log_lazy_channel->log(level, __L3PP_LOG_RECORD) << storm_log_lazy_stream.str(); \
63 } \
64 } \
65 } while (false)
66
67// Same contract as STORM_LOG_LAZY_ON_CHANNEL: `callback` must be `bool(std::ostream&)`, return true to emit.
68#define STORM_LOG_STATISTICS_LAZY(...) STORM_LOG_LAZY_ON_CHANNEL(storm::utility::STATISTICS_LOG_CHANNEL, l3pp::LogLevel::INFO, __VA_ARGS__)
69// Same contract as STORM_LOG_LAZY_ON_CHANNEL: `callback` must be `bool(std::ostream&)`, return true to emit
70#define STORM_LOG_PROGRESS_LAZY(...) STORM_LOG_LAZY_ON_CHANNEL(storm::utility::PROGRESS_LOG_CHANNEL, l3pp::LogLevel::INFO, __VA_ARGS__)
Definition logging.h:5
constexpr const char * STATISTICS_LOG_CHANNEL
Definition logging.h:34
constexpr const char * PROGRESS_LOG_CHANNEL
Definition logging.h:35