Class MsgLogger#
Defined in File MsgLogger.h
Class Documentation#
-
class MsgLogger#
Log messages at different verbosity levels to different loggers.
Use this class to create loggers to files or to the terminal. By default, a terminal sink is active that prints errors and above to stderr and everything with a level below error to stdout. One can change the verbosity of these sinks individually, so each can have a different verbosity.
There are different methods used to log messages. The templated version formats the message similar to how std::format does. The methods that take in a function will only run that function if there is a logger to consume it. Otherwise, the entire function is skipped. This is a clever way to avoid doing computation for variables used only for logging if the messages to be logged are never sent to any loggers.
Public Types
Public Functions
-
~MsgLogger() = default#
Public Static Functions
-
static void addConsoleLogger(level verbosity)#
Add a console logger. This prints errors to stderr and everything else to stdout. The stdout logger is called “stdout” and the stderr logger is called “stderr”.
- Parameters:
verbosity – The verbosity of the stdout logger.
-
static void addFileLogger(const std::filesystem::path &filename, level verbosity)#
Add a file logger. This adds a logger that will print to the given file. The name of the logger is the same as the filename.
- Parameters:
filename – The name of the file to log to.
verbosity – The verbosity of the new file logger.
Add a json logger. This adds a json logger that will print to the given file. The name of the logger is the same as the filename.
- Parameters:
filename – The name of the file to log to.
verbosity – The verbosity of the new file logger.
-
static void removeLogger(const std::string &name)#
Remove a logger.
- Parameters:
name – The name of the logger to remove.
Friends
-
friend void error(msg_f f)#
Write an error to all loggers using a function that outputs a message. This function is only executed if one or more sinks will consume it.
- Parameters:
f – The function that generates the error message
-
friend void warn(msg_f f)#
Write an warn to all loggers using a function that outputs a message. This function is only executed if one or more sinks will consume it.
- Parameters:
f – The function that generates the warn message
-
friend void info(msg_f f)#
Write an info to all loggers using a function that outputs a message. This function is only executed if one or more sinks will consume it.
- Parameters:
f – The function that generates the info message
-
friend void debug(msg_f f)#
Write an debug to all loggers using a function that outputs a message. This function is only executed if one or more sinks will consume it.
- Parameters:
f – The function that generates the debug message
-
friend void trace(msg_f f)#
Write an trace to all loggers using a function that outputs a message. This function is only executed if one or more sinks will consume it.
- Parameters:
f – The function that generates the trace message
-
friend bool _numTraceCheck()#
Check if anything will receive numTrace.
- Returns:
true if there is a num_trace sink. false otherwise.
-
~MsgLogger() = default#