MUSX Document Model
Loading...
Searching...
No Matches
musx::util::Logger Class Reference

A utility class for handling logging with customizable callbacks. More...

#include <Logger.h>

Public Types

enum class  LogLevel { Info , Warning , Error , Verbose }
 Enum class representing the severity levels of log messages. More...
 
using LogCallback = std::function< void(Logger::LogLevel, const std::string &)>
 Type alias for the logging callback function.
 

Static Public Member Functions

static void setCallback (LogCallback callback)
 Sets a custom callback for handling log messages.
 
static LogCallback getCallback ()
 Retrieves the currently set logging callback.
 
static void log (LogLevel level, const std::string &message)
 Logs a message with a specific severity level.
 

Detailed Description

A utility class for handling logging with customizable callbacks.

The Logger class provides a centralized mechanism for logging messages with different severity levels. By default, messages are sent to std::cerr, but a custom logging callback can be registered to handle messages in other ways (e.g., writing to a file, console, or network).

Member Typedef Documentation

◆ LogCallback

using musx::util::Logger::LogCallback = std::function<void(Logger::LogLevel, const std::string&)>

Type alias for the logging callback function.

The callback receives a log level and a message string.

Member Enumeration Documentation

◆ LogLevel

enum class musx::util::Logger::LogLevel
strong

Enum class representing the severity levels of log messages.

Enumerator
Info 

Informational messages for general program operation.

Warning 

Warning messages indicating potential issues.

Error 

Error messages indicating critical issues.

Verbose 

Informational messages that should only displayed when verbose logging is requested.

Member Function Documentation

◆ getCallback()

static LogCallback musx::util::Logger::getCallback ( )
inlinestatic

Retrieves the currently set logging callback.

Returns
The current logging callback function or null if not set.

◆ log()

static void musx::util::Logger::log ( LogLevel  level,
const std::string &  message 
)
inlinestatic

Logs a message with a specific severity level.

Parameters
levelThe severity level of the message.
messageThe message string to log.

If a custom callback is registered, it will handle the message. Otherwise, the default behavior writes the message to std::cerr.

◆ setCallback()

static void musx::util::Logger::setCallback ( LogCallback  callback)
inlinestatic

Sets a custom callback for handling log messages.

Parameters
callbackA function that takes a log level and message string. The callback will be invoked whenever a message is logged. If no callback is provided, messages will default to std::cerr.