56 log(
Level level,
const std::string &subsystem,
const std::string &msg,
57 const std::map<std::string, std::any> *details =
nullptr) = 0;
60 virtual void error(
const std::string &subsystem,
const std::string &msg,
61 const std::map<std::string, std::any> *details =
nullptr) {
66 warning(
const std::string &subsystem,
const std::string &msg,
67 const std::map<std::string, std::any> *details =
nullptr) {
71 virtual void info(
const std::string &subsystem,
const std::string &msg,
72 const std::map<std::string, std::any> *details =
nullptr) {
79 inline void debug(
const std::string &subsystem,
const std::string &msg,
80 const std::map<std::string, std::any> *details =
nullptr) {
91 void(std::string &subsystem, std::string &msg,
92 std::unique_ptr<std::map<std::string, std::any>> &details)>
100 virtual void debugImpl(
const std::string &subsystem,
const std::string &msg,
101 const std::map<std::string, std::any> *details) {
107 void(std::string &subsystem, std::string &msg,
108 std::unique_ptr<std::map<std::string, std::any>> &details)>
112 std::string subsystem;
114 std::unique_ptr<std::map<std::string, std::any>> details =
nullptr;
115 debugFunc(subsystem, msg, details);
116 debugImpl(subsystem, msg, details.get());
131 void log(
Level level,
const std::string &subsystem,
const std::string &msg,
132 const std::map<std::string, std::any> *details)
override final;
137 const std::string &msg,
138 const std::map<std::string, std::any> *details) = 0;
155 const std::string &msg,
156 const std::map<std::string, std::any> *details)
override;
172 void log(
Level,
const std::string &,
const std::string &,
173 const std::map<std::string, std::any> *)
override {}
177 std::string
toString(
const std::any &a);
virtual void error(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an error.
virtual void warning(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report a warning.
virtual void info(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an informational message.
bool debugEnabled
Enable or disable debug messages.
virtual void debugImpl(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details)
Overrideable version of debug. Only gets called if debug is enabled.
virtual ~Logger()=default
void debug(std::function< void(std::string &subsystem, std::string &msg, std::unique_ptr< std::map< std::string, std::any >> &details)> debugFunc)
Call the debug function callback only if debug is enabled then log a debug message.
virtual void debugImpl(std::function< void(std::string &subsystem, std::string &msg, std::unique_ptr< std::map< std::string, std::any >> &details)> debugFunc)
Overrideable version of debug. Only gets called if debug is enabled.
Logger(bool debugEnabled)
void debug(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report a debug message.
virtual void log(Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)=0
Report a log message.
A logger that does nothing.
void log(Level, const std::string &, const std::string &, const std::map< std::string, std::any > *) override
Report a log message.
A logger that writes to a C++ std::ostream.
Level minLevel
The minimum log level to emit.
void logImpl(Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details) override
Subclasses must implement this method to log messages.
std::ostream & outStream
Everything except errors goes here.
std::ostream & errorStream
Just for errors.
StreamLogger(Level minLevel, std::ostream &out, std::ostream &error)
Create a stream logger that logs to the given output stream and error output stream.
A thread-safe logger which calls functions implemented by subclasses.
std::mutex mutex
Mutex to protect the stream from interleaved logging writes.
virtual void logImpl(Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details)=0
Subclasses must implement this method to log messages.
void log(Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details) override final
Grabs the lock and calls logImpl.
std::string toString(const std::any &a)
'Stringify' a std::any. This is used to log std::any values by some loggers.