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

Implements logging configuration and output. More...

#include "src/logging/logger.h"
#include <algorithm>
#include <array>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <string>
#include <utility>
#include <windows.h>
#include <hal/debug.h>
#include <xboxkrnl/xboxkrnl.h>
Include dependency graph for logger.cpp:

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

Implements logging configuration and 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.