ADTF  3.18.2
workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/a_util/logging/log.h
Go to the documentation of this file.
1 
15 #ifndef A_UTIL_UTIL_LOG_HEADER_INCLUDED
16 #define A_UTIL_UTIL_LOG_HEADER_INCLUDED
17 
18 #include <a_util/base/delegate.h>
19 #include <a_util/base/types.h>
20 #include <a_util/preprocessor/to_string.h> // A_UTIL_TO_STRING()
23 
24 namespace a_util {
25 namespace logging {
30 enum LogLevel {
31  None = 0,
32  Error = 10,
33  Warning = 20,
34  Info = 30,
35  Dump = 40,
36  Debug = Dump,
37  All = 0xFF
38 };
39 
41 struct LogEntry {
43  std::uint8_t log_level;
44  std::string message;
45  std::string source;
46 };
47 
52 void addEntry(const LogEntry& entry);
53 
61 void addEntry(std::uint8_t log_level,
62  const std::string& message = a_util::strings::empty_string,
63  const std::string& source = a_util::strings::empty_string);
64 
69 
74 void setLogger(Logger log);
75 
81 
87 std::string defaultFormat(const LogEntry& entry);
88 
93 void defaultLogger(const LogEntry& entry);
94 
100 #define LOG_ADD_ENTRY(__level, ...) \
101  a_util::logging::addEntry(__level, \
102  a_util::strings::format(__VA_ARGS__), \
103  __FILE__ "(" A_UTIL_TO_STRING(__LINE__) ")")
104 
110 #ifdef _DEBUG
111 #define LOG_DUMP(...) LOG_ADD_ENTRY(a_util::logging::Dump, __VA_ARGS__)
112 #else
113 #define LOG_DUMP(...)
114 #endif
115 
117 #define LOG_INFO(...) LOG_ADD_ENTRY(a_util::logging::Info, __VA_ARGS__)
118 
123 #define LOG_WARNING(...) LOG_ADD_ENTRY(a_util::logging::Warning, __VA_ARGS__)
124 
129 #define LOG_ERROR(...) LOG_ADD_ENTRY(a_util::logging::Error, __VA_ARGS__)
130 
131 } // namespace logging
132 } // namespace a_util
133 
134 #endif // A_UTIL_UTIL_LOG_HEADER_INCLUDED
General function template: encapsulates a function or a method with a single parameter.
Common include for delegate functionality.
std::int64_t timestamp_t
Type of a timestamp value. If not otherwise stated, always in microseconds.
experimental::UnaryDelegate< void, const LogEntry & > Logger
Logger interface definition.
void addEntry(const LogEntry &entry)
Adds a new log entry to the current logger.
std::string defaultFormat(const LogEntry &entry)
Get the default string representation of a log entry.
Logger getLogger()
Get the currently used logger.
void setLogger(Logger log)
Sets the currently used logger.
void defaultLogger(const LogEntry &entry)
Default logging method, that writes log messages to stdout.
const std::string empty_string
Contains the empty string.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Public API for string formatting functions.
Public API for string modification and inspection functions.
A log entry.
std::string source
the origin of the entry
std::string message
the message text
std::uint8_t log_level
the log level, see LogLevel.
timestamp_t time_stamp
time stamp of the log message.
Definition of preprocessor macro A_UTIL_TO_STRING.
Public types and functions defining a_util core functionality.