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