14#include <libcamera/base/private.h>
33 static LogCategory *
create(std::string_view
name);
35 const std::string &
name()
const {
return name_; }
45 const std::string name_;
47 std::atomic<LogSeverity> severity_;
48 static_assert(
decltype(severity_)::is_always_lock_free);
51#define LOG_DECLARE_CATEGORY(name) \
52extern const LogCategory &_LOG_CATEGORY(name)();
54#define LOG_DEFINE_CATEGORY(name) \
55LOG_DECLARE_CATEGORY(name) \
56const LogCategory &_LOG_CATEGORY(name)() \
59 static LogCategory *category = LogCategory::create(#name); \
66 LogMessage(
const char *fileName,
unsigned int line,
71 std::ostream &
stream() {
return msgStream_; }
76 const std::string &
fileInfo()
const {
return fileInfo_; }
77 const std::string &
prefix()
const {
return prefix_; }
78 const std::string
msg()
const {
return msgStream_.str(); }
83 std::ostringstream msgStream_;
87 std::string fileInfo_;
100 const char *fileName = __builtin_FILE(),
101 unsigned int line = __builtin_LINE())
const;
105 const char *fileName = __builtin_FILE(),
106 unsigned int line = __builtin_LINE());
109#define _LOG_CATEGORY(name) logCategory##name
111#define _LOG1(severity) \
112 _log(nullptr, Log##severity).stream()
113#define _LOG2(category, severity) \
114 _log(&_LOG_CATEGORY(category)(), Log##severity).stream()
120#define _LOG_MACRO(_1, _2, NAME, ...) NAME
121#define LOG(...) _LOG_MACRO(__VA_ARGS__, _LOG2, _LOG1)(__VA_ARGS__)
123#define LOG(category, severity)
127#define ASSERT(condition) static_cast<void>(({ \
129 LOG(Fatal) << "assertion \"" #condition "\" failed in " \
130 << __func__ << "()"; \
133#define ASSERT(condition) static_cast<void>(false && (condition))
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
A category of log message.
Definition log.h:31
static LogCategory * create(std::string_view name)
Create a new LogCategory or return an existing one.
Definition log.cpp:766
static const LogCategory & defaultCategory()
Retrieve the default log category.
Definition log.cpp:809
const std::string & name() const
Retrieve the log category name.
Definition log.h:35
void setSeverity(LogSeverity severity)
Set the severity of the log category.
Definition log.h:37
LogSeverity severity() const
Retrieve the severity of the log category.
Definition log.h:36
Internal log message representation.
Definition log.h:64
const utils::time_point & timestamp() const
Retrieve the timestamp of the log message.
Definition log.h:73
const LogCategory & category() const
Retrieve the category of the log message.
Definition log.h:75
LogSeverity severity() const
Retrieve the severity of the log message.
Definition log.h:74
const std::string & prefix() const
Retrieve the prefix of the log message.
Definition log.h:77
LogMessage(const char *fileName, unsigned int line, const LogCategory &category, LogSeverity severity, std::string prefix={})
Construct a log message for a given category.
Definition log.cpp:839
const std::string & fileInfo() const
Retrieve the file info of the log message.
Definition log.h:76
const std::string msg() const
Retrieve the message text of the log message.
Definition log.h:78
std::ostream & stream()
Definition log.h:71
Base class to support log message extensions.
Definition log.h:92
LogMessage _log(const LogCategory *category, LogSeverity severity, const char *fileName=__builtin_FILE(), unsigned int line=__builtin_LINE()) const
Create a temporary LogMessage object to log a message.
Definition log.cpp:954
virtual std::string logPrefix() const =0
Retrieve a string to be prefixed to the log message.
Message logger.
Definition log.cpp:298
Top-level libcamera namespace.
Definition backtrace.h:17
LogMessage _log(const LogCategory *category, LogSeverity severity, const char *fileName=__builtin_FILE(), unsigned int line=__builtin_LINE())
Create a temporary LogMessage object to log a message.
Definition log.cpp:974
LogSeverity
Definition log.h:21
@ LogDebug
Definition log.h:23
@ LogInfo
Definition log.h:24
@ LogError
Definition log.h:26
@ LogWarning
Definition log.h:25
@ LogFatal
Definition log.h:27
Miscellaneous utility functions.
std::chrono::steady_clock::time_point time_point
The libcamera time point related to libcamera::utils::clock.
Definition utils.h:74