Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
logger.h File Reference

Declares logging configuration and output. More...

#include <cstddef>
#include <cstdint>
#include <deque>
#include <functional>
#include <mutex>
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for logger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  logging::detail::GlobalLoggingState
 Process-wide mutable logger state shared by the logging helpers. More...
 
struct  logging::LogEntry
 Structured log entry stored by the in-memory logger. More...
 
class  logging::Logger
 Small in-memory logger with a ring buffer and optional sinks. More...
 
struct  logging::LogSourceLocation
 Optional source location captured for a structured log entry. More...
 
struct  logging::LogTimestamp
 Local wall-clock timestamp captured for each retained log entry. More...
 

Typedefs

using logging::LogSink = std::function<void(const LogEntry &entry)>
 Callback invoked for each accepted log entry.
 
using logging::TimestampProvider = std::function<LogTimestamp()>
 Callback that supplies timestamps for new log entries.
 

Enumerations

enum class  logging::LogLevel {
  trace = 0 , debug = 1 , info = 2 , warning = 3 ,
  error = 4 , none = 5
}
 Severity levels used by the Moonlight client logger. More...
 

Functions

bool logging::debug (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a debug entry through the registered global logger.
 
bool logging::error (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record an error entry through the registered global logger.
 
std::string logging::format_entry (const LogEntry &entry)
 Format a log entry for text consoles or overlays.
 
std::string logging::format_source_location (const LogSourceLocation &location)
 Format a source location for text consoles or overlays.
 
std::string logging::format_startup_console_line (LogLevel level, std::string_view category, std::string_view message)
 Format one startup console line without timestamps or source locations.
 
std::string logging::format_timestamp (const LogTimestamp &timestamp)
 Format a local wall-clock timestamp for log prefixes.
 
bool logging::has_global_logger ()
 Return whether a global logger is currently available.
 
bool logging::info (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record an info entry through the registered global logger.
 
bool logging::log (LogLevel level, std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a structured entry through the registered global logger.
 
void logging::print_startup_console_line (LogLevel level, std::string_view category, std::string_view message)
 Print one startup console line when output is enabled.
 
void logging::set_debugger_console_minimum_level (LogLevel minimumLevel)
 Update the debugger-console minimum level on the registered global logger.
 
void logging::set_file_minimum_level (LogLevel minimumLevel)
 Update the runtime file sink minimum level on the registered global logger.
 
void logging::set_file_sink (LogSink sink)
 Install or replace the runtime file sink on the registered global logger.
 
void logging::set_global_logger (Logger *logger)
 Register the process-wide logger used by convenience logging helpers.
 
void logging::set_minimum_level (LogLevel minimumLevel)
 Update the retained in-memory minimum level on the registered global logger.
 
void logging::set_startup_console_enabled (bool enabled)
 Enable or disable startup console output.
 
void logging::set_startup_debug_enabled (bool enabled)
 Enable or disable startup debug mirroring on the registered global logger.
 
std::vector< LogEntrylogging::snapshot (LogLevel minimumLevel=LogLevel::trace)
 Return a filtered snapshot from the registered global logger.
 
bool logging::startup_console_enabled ()
 Return whether startup console output is currently enabled.
 
const char * logging::to_string (LogLevel level)
 Return the display label for a log level.
 
bool logging::trace (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a trace entry through the registered global logger.
 
bool logging::warn (std::string category, std::string message, LogSourceLocation location=LogSourceLocation::current())
 Record a warning entry through the registered global logger.
 

Detailed Description

Declares logging configuration and output.

Enumeration Type Documentation

◆ LogLevel

enum class logging::LogLevel
strong

Severity levels used by the Moonlight client logger.

Enumerator
trace 

Verbose diagnostic output intended for deep tracing.

debug 

Debug output for development and troubleshooting.

info 

Informational output for normal application activity.

warning 

Recoverable issue or degraded behavior.

error 

Failure that prevented an operation from completing.

none 

Sentinel level used to disable output.

Function Documentation

◆ debug()

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

Record a debug entry through the registered global logger.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationSource location for the entry.
Returns
true if the entry was accepted by the registered logger.

◆ error()

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

Record an error entry through the registered global logger.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationSource location for the entry.
Returns
true if the entry was accepted by the registered logger.

◆ format_entry()

std::string logging::format_entry ( const LogEntry & entry)

Format a log entry for text consoles or overlays.

Parameters
entryThe entry to format.
Returns
A formatted log line.

◆ format_source_location()

std::string logging::format_source_location ( const LogSourceLocation & location)

Format a source location for text consoles or overlays.

Parameters
locationSource location to format.
Returns
A normalized file:line string, or an empty string when unavailable.

◆ format_startup_console_line()

std::string logging::format_startup_console_line ( LogLevel level,
std::string_view category,
std::string_view message )
nodiscard

Format one startup console line without timestamps or source locations.

Parameters
levelStructured log level to display.
categoryShort subsystem category such as startup or sdl.
messageHuman-readable console text.
Returns
Formatted startup console line without a trailing newline.

◆ format_timestamp()

std::string logging::format_timestamp ( const LogTimestamp & timestamp)

Format a local wall-clock timestamp for log prefixes.

Parameters
timestampLocal timestamp to format.
Returns
A stable YYYY-MM-DD HH:MM:SS.mmm timestamp string.

◆ has_global_logger()

bool logging::has_global_logger ( )
nodiscard

Return whether a global logger is currently available.

Returns
true when the convenience logging helpers can emit entries.

◆ info()

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

Record an info entry through the registered global logger.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationSource location for the entry.
Returns
true if the entry was accepted by the registered logger.

◆ log()

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

Record a structured entry through the registered global logger.

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

◆ print_startup_console_line()

void logging::print_startup_console_line ( LogLevel level,
std::string_view category,
std::string_view message )

Print one startup console line when output is enabled.

Parameters
levelStructured log level to display.
categoryShort subsystem category such as startup or sdl.
messageHuman-readable console text.

◆ set_debugger_console_minimum_level()

void logging::set_debugger_console_minimum_level ( LogLevel minimumLevel)

Update the debugger-console minimum level on the registered global logger.

Parameters
minimumLevelEntries below this level are not mirrored to DbgPrint().

◆ set_file_minimum_level()

void logging::set_file_minimum_level ( LogLevel minimumLevel)

Update the runtime file sink minimum level on the registered global logger.

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

◆ set_file_sink()

void logging::set_file_sink ( LogSink sink)

Install or replace the runtime file sink on the registered global logger.

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

◆ set_global_logger()

void logging::set_global_logger ( Logger * logger)

Register the process-wide logger used by convenience logging helpers.

Parameters
loggerLogger instance to expose globally, or nullptr to clear it.

◆ set_minimum_level()

void logging::set_minimum_level ( LogLevel minimumLevel)

Update the retained in-memory minimum level on the registered global logger.

Parameters
minimumLevelEntries below this level are not kept in memory.

◆ set_startup_console_enabled()

void logging::set_startup_console_enabled ( bool enabled)

Enable or disable startup console output.

Parameters
enabledTrue to allow future startup console writes.

◆ set_startup_debug_enabled()

void logging::set_startup_debug_enabled ( bool enabled)

Enable or disable startup debug mirroring on the registered global logger.

Parameters
enabledTrue to mirror future entries to the pre-splash startup console.

◆ snapshot()

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

Return a filtered snapshot from the registered global logger.

Parameters
minimumLevelMinimum level to include in the returned snapshot.
Returns
Filtered retained entries, or an empty vector when no logger is registered.

◆ startup_console_enabled()

bool logging::startup_console_enabled ( )
nodiscard

Return whether startup console output is currently enabled.

Returns
true when pre-splash console lines should still be emitted.

◆ to_string()

const char * logging::to_string ( LogLevel level)

Return the display label for a log level.

Parameters
levelThe level to stringify.
Returns
A stable, uppercase label.

◆ trace()

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

Record a trace entry through the registered global logger.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationSource location for the entry.
Returns
true if the entry was accepted by the registered logger.

◆ warn()

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

Record a warning entry through the registered global logger.

Parameters
categorySubsystem name such as ui or streaming.
messageUser-visible message text.
locationSource location for the entry.
Returns
true if the entry was accepted by the registered logger.