ADTF File Library
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
16
17#pragma once
18#include <string_view>
19#include <cstdint>
20#include <string_view>
21#include <string>
22#include <chrono>
23
24namespace adtf_file
25{
26
28enum class LogLevel : uint8_t
29{
30 None = 0,
31 Error = 10,
32 Warning = 20,
33 Info = 30,
34 Detail = 35,
35 Dump = 40,
37 All = 0xFF
38};
39
42{
44 std::string_view file;
45 size_t line;
46 std::string_view function;
47};
48
51{
52 std::chrono::system_clock::time_point timestamp;
54 std::string_view message;
56};
57
66class Logger
67{
68public:
77 virtual void log(std::chrono::system_clock::time_point timestamp,
78 LogLevel log_level,
79 std::string_view message,
80 SourceLocation location) noexcept = 0;
81};
82
91Logger& getLogger() noexcept;
92
103
110bool getTerminalColorSupport(FILE* output) noexcept;
111
125std::string defaultLogFormat(std::chrono::system_clock::time_point timestamp,
126 LogLevel log_level,
127 std::string_view message,
128 SourceLocation location,
129 bool bWithColor) noexcept;
130
133#define ADTF_FILE_CURRENT_SOURCE_LOCATION() \
134 adtf_file::SourceLocation \
135 { \
136 __FILE__, __LINE__, __func__ \
137 }
139
148#define ADTF_FILE_LOG(__level, __message) \
149 adtf_file::getLogger().log(std::chrono::system_clock::now(), __level, __message, \
150 ADTF_FILE_CURRENT_SOURCE_LOCATION())
151
153#define ADTF_FILE_LOG_DUMP(__message) ADTF_FILE_LOG(adtf_file::LogLevel::Dump, __message)
155#define ADTF_FILE_LOG_DETAIL(__message) ADTF_FILE_LOG(adtf_file::LogLevel::Detail, __message)
157#define ADTF_FILE_LOG_INFO(__message) ADTF_FILE_LOG(adtf_file::LogLevel::Info, __message)
159#define ADTF_FILE_LOG_WARNING(__message) ADTF_FILE_LOG(adtf_file::LogLevel::Warning, __message)
161#define ADTF_FILE_LOG_ERROR(__message) ADTF_FILE_LOG(adtf_file::LogLevel::Error, __message)
162
163} // namespace adtf_file
164
165extern "C"
166{
181#ifdef _WIN32
182 __declspec(dllimport)
183#endif
185}
Abstract sink for log messages produced by the adtf_file library.
Definition log.h:67
virtual void log(std::chrono::system_clock::time_point timestamp, LogLevel log_level, std::string_view message, SourceLocation location) noexcept=0
Emit a single log event.
void adtfFileSetLogger(adtf_file::Logger *logger)
Injects a host-provided logger into the plugin.
namespace for ADTF File library
Definition adtf2_adtf_core_media_sample_deserializer.h:25
std::string defaultLogFormat(std::chrono::system_clock::time_point timestamp, LogLevel log_level, std::string_view message, SourceLocation location, bool bWithColor) noexcept
Formats a log event into a human-readable string.
Logger & getLogger() noexcept
Returns the active logger used by the library.
Logger & getDefaultLogger() noexcept
Returns the built-in default logger.
LogLevel
Severity levels for log messages, ordered from least to most verbose.
Definition log.h:29
@ Warning
Potentially harmful situations that do not abort processing.
Definition log.h:32
@ Info
General informational messages about normal operation.
Definition log.h:33
@ None
Logging disabled; no messages are emitted.
Definition log.h:30
@ Error
Unrecoverable errors that require immediate attention.
Definition log.h:31
@ Detail
More detailed operational messages for diagnostics.
Definition log.h:34
@ Debug
Alias for Dump.
Definition log.h:36
@ All
Enable all log levels.
Definition log.h:37
@ Dump
Verbose data dumps for deep troubleshooting.
Definition log.h:35
bool getTerminalColorSupport(FILE *output) noexcept
Queries whether the current terminal supports ANSI color sequences.
Bundles all data associated with a single log event.
Definition log.h:51
SourceLocation location
Source code location that produced the entry.
Definition log.h:55
LogLevel log_level
Severity of the message.
Definition log.h:53
std::chrono::system_clock::time_point timestamp
Wall-clock time when the event occurred.
Definition log.h:52
std::string_view message
Human-readable description of the event.
Definition log.h:54
Identifies the source code location where a log message was emitted.
Definition log.h:42
std::string_view function
Name of the enclosing function (typically __func__).
Definition log.h:46
std::string_view file
Path of the translation unit (typically __FILE__).
Definition log.h:44
size_t line
Line number within file (typically __LINE__).
Definition log.h:45