60 log(
Level level,
const std::string &subsystem,
const std::string &msg,
61 const std::map<std::string, std::any> *details =
nullptr) = 0;
64 virtual void error(
const std::string &subsystem,
const std::string &msg,
65 const std::map<std::string, std::any> *details =
nullptr) {
70 warning(
const std::string &subsystem,
const std::string &msg,
71 const std::map<std::string, std::any> *details =
nullptr) {
75 virtual void info(
const std::string &subsystem,
const std::string &msg,
76 const std::map<std::string, std::any> *details =
nullptr) {
83 inline void debug(
const std::string &subsystem,
const std::string &msg,
84 const std::map<std::string, std::any> *details =
nullptr) {
95 void(std::string &subsystem, std::string &msg,
96 std::unique_ptr<std::map<std::string, std::any>> &details)>
106 inline void trace(
const std::string &subsystem,
const std::string &msg,
107 const std::map<std::string, std::any> *details =
nullptr) {
108#ifdef ESI_RUNTIME_TRACE
117 void(std::string &subsystem, std::string &msg,
118 std::unique_ptr<std::map<std::string, std::any>> &details)>
120#ifdef ESI_RUNTIME_TRACE
123 std::string subsystem;
125 std::unique_ptr<std::map<std::string, std::any>> details =
nullptr;
126 traceFunc(subsystem, msg, details);
133 virtual void debugImpl(
const std::string &subsystem,
const std::string &msg,
134 const std::map<std::string, std::any> *details) {
140 void(std::string &subsystem, std::string &msg,
141 std::unique_ptr<std::map<std::string, std::any>> &details)>
145 std::string subsystem;
147 std::unique_ptr<std::map<std::string, std::any>> details =
nullptr;
148 debugFunc(subsystem, msg, details);
149 debugImpl(subsystem, msg, details.get());
167 void log(
Level level,
const std::string &subsystem,
const std::string &msg,
168 const std::map<std::string, std::any> *details)
override final;
173 const std::string &msg,
174 const std::map<std::string, std::any> *details) = 0;
191 const std::string &msg,
192 const std::map<std::string, std::any> *details)
override;
210 const std::string &msg,
211 const std::map<std::string, std::any> *details)
override;
222 void log(
Level,
const std::string &,
const std::string &,
223 const std::map<std::string, std::any> *)
override {}
227std::string
toString(
const std::any &a);
A logger that writes to the console. Includes color support.
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.
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.
bool traceEnabled
Enable or disable trace messages.
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 trace(std::function< void(std::string &subsystem, std::string &msg, std::unique_ptr< std::map< std::string, std::any > > &details)> traceFunc)
Log a trace message using a callback.
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.
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.
void debug(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report a debug message.
void trace(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Log a trace message.
Logger(bool debugEnabled, bool traceEnabled)
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.