Dev Essential  1.6.3
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
14
15#ifndef A_UTIL_UTIL_LOG_HEADER_INCLUDED
16#define A_UTIL_UTIL_LOG_HEADER_INCLUDED
17
19#include <a_util/base/types.h>
20#include <a_util/preprocessor/to_string.h> // A_UTIL_TO_STRING()
23
24namespace a_util {
25namespace logging {
31 None = 0,
32 Error = 10,
33 Warning = 20,
34 Info = 30,
35 Dump = 40,
37 All = 0xFF
38};
39
41struct LogEntry {
43 std::uint8_t log_level;
44 std::string message;
45 std::string source;
46};
47
52void addEntry(const LogEntry& entry);
53
61void 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
74void setLogger(Logger log);
75
81
87std::string defaultFormat(const LogEntry& entry);
88
93void 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
Definition delegate_decl.h:163
std::int64_t timestamp_t
Type of a timestamp value. If not otherwise stated, always in microseconds.
Definition types.h:31
Serves as component for basic logging functionality.
Definition logging.h:20
void addEntry(const LogEntry &entry)
std::string defaultFormat(const LogEntry &entry)
Logger getLogger()
void setLogger(Logger log)
experimental::UnaryDelegate< void, const LogEntry & > Logger
Definition log.h:68
LogLevel
Definition log.h:30
@ All
Log all messages.
Definition log.h:37
@ Debug
Same as Dump.
Definition log.h:36
@ Error
Log errors only.
Definition log.h:32
@ Info
Log errors, warnings and info messages.
Definition log.h:34
@ None
Log nothing.
Definition log.h:31
@ Dump
Log errors, warnings, info and debug messages.
Definition log.h:35
@ Warning
Log errors and warnings.
Definition log.h:33
void defaultLogger(const LogEntry &entry)
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
A log entry.
Definition log.h:41
std::string message
the message text
Definition log.h:44
std::string source
the origin of the entry
Definition log.h:45
timestamp_t time_stamp
time stamp of the log message.
Definition log.h:42
std::uint8_t log_level
the log level, see LogLevel.
Definition log.h:43