ADTF  3.14.3
log.h
Go to the documentation of this file.
1 
21 #ifndef A_UTIL_UTIL_LOG_HEADER_INCLUDED
22 #define A_UTIL_UTIL_LOG_HEADER_INCLUDED
23 
24 #include <a_util/base/delegate.h>
25 #include <a_util/base/types.h>
26 #include <a_util/preprocessor/to_string.h> // A_UTIL_TO_STRING()
29 
30 namespace a_util {
31 namespace logging {
36 enum LogLevel {
37  None = 0,
38  Error = 10,
39  Warning = 20,
40  Info = 30,
41  Dump = 40,
42  Debug = Dump,
43  All = 0xFF
44 };
45 
47 struct LogEntry {
49  std::uint8_t log_level;
50  std::string message;
51  std::string source;
52 };
53 
58 void addEntry(const LogEntry& entry);
59 
67 void addEntry(std::uint8_t log_level,
68  const std::string& message = a_util::strings::empty_string,
69  const std::string& source = a_util::strings::empty_string);
70 
75 
80 void setLogger(Logger log);
81 
87 
93 std::string defaultFormat(const LogEntry& entry);
94 
99 void defaultLogger(const LogEntry& entry);
100 
106 #define LOG_ADD_ENTRY(__level, ...) \
107  a_util::logging::addEntry(__level, \
108  a_util::strings::format(__VA_ARGS__), \
109  __FILE__ "(" A_UTIL_TO_STRING(__LINE__) ")")
110 
116 #ifdef _DEBUG
117 #define LOG_DUMP(...) LOG_ADD_ENTRY(a_util::logging::Dump, __VA_ARGS__)
118 #else
119 #define LOG_DUMP(...)
120 #endif
121 
123 #define LOG_INFO(...) LOG_ADD_ENTRY(a_util::logging::Info, __VA_ARGS__)
124 
129 #define LOG_WARNING(...) LOG_ADD_ENTRY(a_util::logging::Warning, __VA_ARGS__)
130 
135 #define LOG_ERROR(...) LOG_ADD_ENTRY(a_util::logging::Error, __VA_ARGS__)
136 
137 } // namespace logging
138 } // namespace a_util
139 
140 #endif // A_UTIL_UTIL_LOG_HEADER_INCLUDED
General function template: encapsulates a function or a method with a single parameter.
Public types and functions defining a_util core functionality.
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.
Definition: log.h:74
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.
LogLevel
Usable log levels for LogEntry::log_level.
Definition: log.h:36
@ Dump
Log errors, warnings, info and debug messages.
Definition: log.h:41
@ Info
Log errors, warnings and info messages.
Definition: log.h:40
@ Warning
Log errors and warnings.
Definition: log.h:39
@ Error
Log errors only.
Definition: log.h:38
@ All
Log all messages.
Definition: log.h:43
@ Debug
Same as Dump.
Definition: log.h:42
@ None
Log nothing.
Definition: log.h:37
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:30
Public API for string formatting functions.
Public API for string modification and inspection functions.
A log entry.
Definition: log.h:47
std::string source
the origin of the entry
Definition: log.h:51
std::string message
the message text
Definition: log.h:50
std::uint8_t log_level
the log level, see LogLevel.
Definition: log.h:49
timestamp_t time_stamp
time stamp of the log message.
Definition: log.h:48
Definition of preprocessor macro A_UTIL_TO_STRING.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)