diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-02-08 16:40:57 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2019-02-11 11:23:51 +0200 |
commit | 8a401ed4119aac4ca994f70cb5540bc1b2c6939a (patch) | |
tree | f14a6eecb27b8db376351c331cce40d1d410cc5d /src/libcamera/include | |
parent | d8f2ed7d0d7f0de7184916da59cd2097529bd1c9 (diff) |
libcamera: log: Allow extending log messages
Introduce a base Loggable class that can be inherited from by other
classes to support adding per-instance information to the log messages.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/libcamera/include')
-rw-r--r-- | src/libcamera/include/log.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h index ad8f8452..8ea5a1eb 100644 --- a/src/libcamera/include/log.h +++ b/src/libcamera/include/log.h @@ -54,6 +54,7 @@ public: LogMessage(const char *fileName, unsigned int line, const LogCategory &category, LogSeverity severity); LogMessage(const LogMessage &) = delete; + LogMessage(LogMessage &&); ~LogMessage(); std::ostream &stream() { return msgStream_; } @@ -66,13 +67,31 @@ private: LogSeverity severity_; }; +class Loggable +{ +public: + virtual ~Loggable(); + +protected: + virtual std::string logPrefix() const = 0; + + LogMessage _log(const char *file, unsigned int line, + LogSeverity severity); + LogMessage _log(const char *file, unsigned int line, + const LogCategory &category, LogSeverity severity); +}; + +LogMessage _log(const char *file, unsigned int line, LogSeverity severity); +LogMessage _log(const char *file, unsigned int line, + const LogCategory &category, LogSeverity severity); + #ifndef __DOXYGEN__ #define _LOG_CATEGORY(name) logCategory##name #define _LOG1(severity) \ - LogMessage(__FILE__, __LINE__, Log##severity).stream() + _log(__FILE__, __LINE__, Log##severity).stream() #define _LOG2(category, severity) \ - LogMessage(__FILE__, __LINE__, _LOG_CATEGORY(category)(), Log##severity).stream() + _log(__FILE__, __LINE__, _LOG_CATEGORY(category)(), Log##severity).stream() /* * Expand the LOG() macro to _LOG1() or _LOG2() based on the number of |