Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Logging::ConsoleSink Class Referenceexport

Thread-safe logging sink that writes formatted records to the console. More...

Inheritance diagram for Mila::Logging::ConsoleSink:
Mila::Logging::Logger

Public Member Functions

 ConsoleSink (LogLevel initialLevel=LogLevel::Info)
 Constructs a ConsoleSink with the specified minimum log level.
LogLevel getLevel () const override
 Returns the current minimum log level.
bool isEnabled (LogLevel level) const override
 Returns true if records at level would be emitted.
void log (std::string_view message, LogLevel level, const std::source_location &location=std::source_location::current()) override
 Emits a record at an explicitly specified level.
void log_critical (std::string_view message, const std::source_location &location=std::source_location::current()) override
 Emits a record at Critical level. Output goes to std::cerr.
void log_debug (std::string_view message, const std::source_location &location=std::source_location::current()) override
 Emits a record at Debug level.
void log_error (std::string_view message, const std::source_location &location=std::source_location::current()) override
 Emits a record at Error level. Output goes to std::cerr.
void log_info (std::string_view message, const std::source_location &location=std::source_location::current()) override
 Emits a record at Info level.
void log_trace (std::string_view message, const std::source_location &location=std::source_location::current()) override
 Emits a record at Trace level.
void log_warning (std::string_view message, const std::source_location &location=std::source_location::current()) override
 Emits a record at Warning level.
void setIncludeSourceLocation (bool include)
 Controls whether source location (file, line, function) is prepended to each record.
void setIncludeTimestamp (bool include)
 Controls whether a timestamp prefix is prepended to each record.
void setLevel (LogLevel level) override
 Sets the minimum level at which records are emitted.
Public Member Functions inherited from Mila::Logging::Logger
 Logger (const Logger &)=delete
 Logger (Logger &&)=delete
Logger & operator= (const Logger &)=delete
Logger & operator= (Logger &&)=delete

Additional Inherited Members

Static Public Member Functions inherited from Mila::Logging::Logger
static void critical (std::string_view message, const std::source_location &location=std::source_location::current())
 Emits a record at Critical level via the default logger.
static void debug (std::string_view message, const std::source_location &location=std::source_location::current())
 Emits a record at Debug level via the default logger.
static Logger & defaultLogger ()
 Returns a reference to the registered default logger.
static void error (std::string_view message, const std::source_location &location=std::source_location::current())
 Emits a record at Error level via the default logger.
static void info (std::string_view message, const std::source_location &location=std::source_location::current())
 Emits a record at Info level via the default logger.
static void setDefaultLogger (Logger *logger)
 Registers a sink as the process-wide default logger.
static void trace (std::string_view message, const std::source_location &location=std::source_location::current())
 Emits a record at Trace level via the default logger.
static void warning (std::string_view message, const std::source_location &location=std::source_location::current())
 Emits a record at Warning level via the default logger.

Detailed Description

Thread-safe logging sink that writes formatted records to the console.

Implements the Logger interface, routing records at Error level and above to std::cerr and all others to std::cout. Each record is prefixed with an optional timestamp and source location to aid diagnostics.

Sink selection is an application-level concern. Wire this sink via Mila::initializeLogger() for CLI or development scenarios.

// Typical wiring in main or Mila::initialize():
auto sink = std::make_shared<Mila::Logging::ConsoleSink>( Mila::Logging::LogLevel::Info );
@ Info
Normal operational milestones (model loaded, server ready).
Definition Logger.ixx:44
static void setDefaultLogger(Logger *logger)
Registers a sink as the process-wide default logger.
Definition Logger.ixx:87

Constructor & Destructor Documentation

◆ ConsoleSink()

Mila::Logging::ConsoleSink::ConsoleSink ( LogLevel initialLevel = LogLevel::Info)
inlineexplicit

Constructs a ConsoleSink with the specified minimum log level.

Parameters
initialLevelRecords below this level are silently discarded.

Member Function Documentation

◆ getLevel()

LogLevel Mila::Logging::ConsoleSink::getLevel ( ) const
inlineoverridevirtual

Returns the current minimum log level.

Implements Mila::Logging::Logger.

◆ isEnabled()

bool Mila::Logging::ConsoleSink::isEnabled ( LogLevel level) const
inlineoverridevirtual

Returns true if records at level would be emitted.

Parameters
levelThe level to test.

Implements Mila::Logging::Logger.

◆ log()

void Mila::Logging::ConsoleSink::log ( std::string_view message,
LogLevel level,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at an explicitly specified level.

Parameters
messageThe log message.
levelThe severity level for this record.
locationAutomatically captured call-site location.

Implements Mila::Logging::Logger.

◆ log_critical()

void Mila::Logging::ConsoleSink::log_critical ( std::string_view message,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at Critical level. Output goes to std::cerr.

Implements Mila::Logging::Logger.

◆ log_debug()

void Mila::Logging::ConsoleSink::log_debug ( std::string_view message,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at Debug level.

Implements Mila::Logging::Logger.

◆ log_error()

void Mila::Logging::ConsoleSink::log_error ( std::string_view message,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at Error level. Output goes to std::cerr.

Implements Mila::Logging::Logger.

◆ log_info()

void Mila::Logging::ConsoleSink::log_info ( std::string_view message,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at Info level.

Implements Mila::Logging::Logger.

◆ log_trace()

void Mila::Logging::ConsoleSink::log_trace ( std::string_view message,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at Trace level.

Implements Mila::Logging::Logger.

◆ log_warning()

void Mila::Logging::ConsoleSink::log_warning ( std::string_view message,
const std::source_location & location = std::source_location::current() )
inlineoverridevirtual

Emits a record at Warning level.

Implements Mila::Logging::Logger.

◆ setIncludeSourceLocation()

void Mila::Logging::ConsoleSink::setIncludeSourceLocation ( bool include)
inline

Controls whether source location (file, line, function) is prepended to each record.

Parameters
includePass false to suppress location info.

◆ setIncludeTimestamp()

void Mila::Logging::ConsoleSink::setIncludeTimestamp ( bool include)
inline

Controls whether a timestamp prefix is prepended to each record.

Parameters
includePass false to suppress timestamps (e.g. in unit tests).

◆ setLevel()

void Mila::Logging::ConsoleSink::setLevel ( LogLevel level)
inlineoverridevirtual

Sets the minimum level at which records are emitted.

Implements Mila::Logging::Logger.


The documentation for this class was generated from the following file: