Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
logging::Logger Class Reference

Small in-memory logger with a ring buffer and optional sinks. More...

#include <src/logging/logger.h>

Public Member Functions

void add_sink (LogSink sink, LogLevel minimumLevel=LogLevel::trace)
 Register an observer that receives accepted entries.
 
std::size_t capacity () const
 Return the maximum number of retained entries.
 
bool debug (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a debug entry.
 
LogLevel debugger_console_minimum_level () const
 Return the minimum level mirrored through DbgPrint() for xemu.
 
const std::deque< LogEntry > & entries () const
 Return the retained entries.
 
bool error (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record an error entry.
 
LogLevel file_minimum_level () const
 Return the minimum level written to the configured file sink.
 
bool info (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record an info entry.
 
bool log (LogLevel level, std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a structured entry.
 
 Logger (std::size_t capacity=256, TimestampProvider timestampProvider={})
 Construct a logger with the provided entry capacity.
 
LogLevel minimum_level () const
 Return the minimum retained in-memory log level.
 
void set_debugger_console_minimum_level (LogLevel minimumLevel)
 Set the minimum level mirrored through DbgPrint() for xemu.
 
void set_file_minimum_level (LogLevel minimumLevel)
 Set the minimum level written to the configured file sink.
 
void set_file_sink (LogSink sink)
 Install or replace the runtime file sink callback.
 
void set_minimum_level (LogLevel minimumLevel)
 Set the minimum retained in-memory log level.
 
void set_startup_debug_enabled (bool enabled)
 Enable or disable pre-splash startup output through debugPrint().
 
bool should_log (LogLevel level) const
 Return whether a log level would be recorded by any enabled sink.
 
std::vector< LogEntrysnapshot (LogLevel minimumLevel=LogLevel::trace) const
 Copy retained entries at or above the requested level.
 
bool startup_debug_enabled () const
 Return whether pre-splash startup output is currently enabled.
 
bool trace (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a trace entry.
 
bool warn (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a warning entry.
 

Detailed Description

Small in-memory logger with a ring buffer and optional sinks.

Constructor & Destructor Documentation

◆ Logger()

logging::Logger::Logger ( std::size_t capacity = 256,
TimestampProvider timestampProvider = {} )
explicit

Construct a logger with the provided entry capacity.

Parameters
capacityMaximum number of retained entries.
timestampProviderOptional timestamp callback used for new entries.

Member Function Documentation

◆ add_sink()

void logging::Logger::add_sink ( LogSink sink,
LogLevel minimumLevel = LogLevel::trace )

Register an observer that receives accepted entries.

Parameters
sinkCallback invoked synchronously during logging.
minimumLevelEntries below this level are not dispatched to the sink.

◆ capacity()

std::size_t logging::Logger::capacity ( ) const

Return the maximum number of retained entries.

Returns
Maximum number of retained entries.

◆ debug()

bool logging::Logger::debug ( std::string category,
std::string message,
LogSourceLocation location = LogSourceLocation::current() )

Record a debug entry.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationOptional source location for the entry.
Returns
true if the entry was accepted.

◆ debugger_console_minimum_level()

LogLevel logging::Logger::debugger_console_minimum_level ( ) const

Return the minimum level mirrored through DbgPrint() for xemu.

Returns
Minimum accepted level for debugger-console output.

◆ entries()

const std::deque< LogEntry > & logging::Logger::entries ( ) const

Return the retained entries.

Returns
Immutable view of the retained ring-buffer contents.

◆ error()

bool logging::Logger::error ( std::string category,
std::string message,
LogSourceLocation location = LogSourceLocation::current() )

Record an error entry.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationOptional source location for the entry.
Returns
true if the entry was accepted.

◆ file_minimum_level()

LogLevel logging::Logger::file_minimum_level ( ) const

Return the minimum level written to the configured file sink.

Returns
Minimum accepted level for the file sink.

◆ info()

bool logging::Logger::info ( std::string category,
std::string message,
LogSourceLocation location = LogSourceLocation::current() )

Record an info entry.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationOptional source location for the entry.
Returns
true if the entry was accepted.

◆ log()

bool logging::Logger::log ( LogLevel level,
std::string category,
std::string message,
LogSourceLocation location = LogSourceLocation::current() )

Record a structured entry.

Parameters
levelSeverity for the entry.
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationOptional source location for the entry.
Returns
true if the entry was accepted.

◆ minimum_level()

LogLevel logging::Logger::minimum_level ( ) const

Return the minimum retained in-memory log level.

Returns
Minimum retained level.

◆ set_debugger_console_minimum_level()

void logging::Logger::set_debugger_console_minimum_level ( LogLevel minimumLevel)

Set the minimum level mirrored through DbgPrint() for xemu.

Parameters
minimumLevelEntries below this level are not written to the debugger console.

◆ set_file_minimum_level()

void logging::Logger::set_file_minimum_level ( LogLevel minimumLevel)

Set the minimum level written to the configured file sink.

Parameters
minimumLevelEntries below this level are not written to the file sink.

◆ set_file_sink()

void logging::Logger::set_file_sink ( LogSink sink)

Install or replace the runtime file sink callback.

Parameters
sinkCallback invoked for entries accepted by the file minimum level.

◆ set_minimum_level()

void logging::Logger::set_minimum_level ( LogLevel minimumLevel)

Set the minimum retained in-memory log level.

Parameters
minimumLevelEntries below this level are not stored in the ring buffer.

◆ set_startup_debug_enabled()

void logging::Logger::set_startup_debug_enabled ( bool enabled)

Enable or disable pre-splash startup output through debugPrint().

Parameters
enabledTrue to mirror future log entries to the startup console.

◆ should_log()

bool logging::Logger::should_log ( LogLevel level) const

Return whether a log level would be recorded by any enabled sink.

Parameters
levelThe candidate level.
Returns
true if the entry would be stored or dispatched.

◆ snapshot()

std::vector< LogEntry > logging::Logger::snapshot ( LogLevel minimumLevel = LogLevel::trace) const

Copy retained entries at or above the requested level.

Parameters
minimumLevelMinimum level to include in the snapshot.
Returns
Filtered log entries in insertion order.

◆ startup_debug_enabled()

bool logging::Logger::startup_debug_enabled ( ) const

Return whether pre-splash startup output is currently enabled.

Returns
true when future log entries are still mirrored to debugPrint().

◆ trace()

bool logging::Logger::trace ( std::string category,
std::string message,
LogSourceLocation location = LogSourceLocation::current() )

Record a trace entry.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationOptional source location for the entry.
Returns
true if the entry was accepted.

◆ warn()

bool logging::Logger::warn ( std::string category,
std::string message,
LogSourceLocation location = LogSourceLocation::current() )

Record a warning entry.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationOptional source location for the entry.
Returns
true if the entry was accepted.

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