Overview / Foundation

log

Logging to file, console and debugger output, in synchronous or asynchronous mode.

Always compiled: part of the core build.Include #include <ethereal/cpp/log/log.hpp>C layer

log.hpp

#include <ethereal/cpp/log/log.hpp>
enum

ELoggingBufferSizes

Ethereal::Logging#
C++
enum class ELoggingBufferSizes : ETL_UINT8
{
    /// @brief    Minimum : Fixed buffer size prepared on @Stack with 64 bytes.
    ///
    eTinyBuffer,

    /// @brief    Small : Fixed buffer size prepared on @Stack with 128 bytes.
    ///
    eSmallBuffer,

    /// @brief    Medium : Fixed buffer size prepared on @Stack with 256 bytes.
    ///            Generally recommended for most cases.
    ///            ** This is the default mode.
    ///
    eMediumBuffer,

    /// @brief    Large : Fixed buffer size prepared on @Stack with 512 bytes.
    ///
    eLargeBuffer,

    /// @brief    Big : Fixed buffer size prepared on @Stack with 1024 bytes.
    ///            This size should only be selected if you are certain that logs with at least 512+ characters will be passed at once to @LogPrintf & @LogStdPrint.
    ///
    eBigBuffer,

    /// @brief    Huge : Fixed buffer size prepared on @Stack with 2048 bytes.
    ///            This size should only be selected if you are certain that logs with at least 1024+ characters will be passed at once to @LogPrintf & @LogStdPrint.
    ///            Generally, logs this large should be split or avoided.
    ///            Choose this size only if you know what you are doing.
    ///
    eHugeBuffer
};

Identification of fixed buffer sizes.

function

GetLogBufferSize

Ethereal::Logging#
constexpr std::size_t GetLogBufferSize( ELoggingBufferSizes BufferSizeID ) noexcept

Retrieves the fixed buffer size in bytes according to its identifier.

BufferSizeID
Identifier of the fixed buffer for log message formatting. See ELoggingBufferSizes.
Fixed buffer size.
enum

ELoggingModes

Ethereal::Logging#
C++
enum class ELoggingModes : ETL_UINT8
{
    /// @brief  Default : The log is executed on the application's main thread, performing a lock during formatting until writing to files is complete.
    ///
    eSyncMode,

    /// @brief  The log is stored as soon as the function is called, but writing to files occurs on the next call to @ref LogTick.
    ///         It is mandatory to call @ref LogTick in the application's main execution or main loop for logs to be written to outputs.
    ///         Without calling @ref LogTick, logs will not be sent to outputs or the log file.
    ///
    eAsyncPostOperation,

    /// @brief  The log is stored as soon as the function is called, but writing to files is performed immediately under an additional routine (thread).
    ///
    eAsyncOtherThread
};

Identification of logging modes.

enum

ELoggingLevel

Ethereal::Logging#
C++
enum class ELoggingLevel : ETL_UINT8
{
    /// @brief    Low level.
    eLow = 0,

    /// @brief    Medium level.
    eMedium,

    /// @brief    High level.
    eHigh,

    /// @brief    Full log.
    eFull,

    /// @brief    Array-only (for internal checks only, never use).
    eLast
};

Identification of log levels.

function

LoggingLevelToString

Ethereal::Logging#
const char * LoggingLevelToString( const ELoggingLevel Level ) noexcept;

Retrieves the log level as a C-string.

Log level in C-string format.
enum

ELoggingTypes

Ethereal::Logging#
C++
enum class ELoggingTypes : ETL_UINT8
{
    /// @brief    Generic.
    eGeneric = 0,

    /// @brief    Informational.
    eInfo,

    /// @brief    Warning.
    eWarning,

    /// @brief    Error.
    eError,

    /// @brief    Debug.
    eDebug,

    /// @brief    Array-only (for internal checks only, never use).
    eLast
};

Identification of log types.

function

LoggingTypeToString

Ethereal::Logging#
const char * LoggingTypeToString( const ELoggingTypes Type ) noexcept;

Retrieves the log type as a C-string.

Log type in C-string format.
function

LogInitialize

Ethereal::Logging#
ETL_INT32 LogInitialize( const char * LogFileNameAndPath, const bool bPrintDateTime = false, const bool bPrintToConsoleOutput = false, const bool bPrintToDebugOutput = false, const ELoggingLevel LogLevel = ELoggingLevel::eLow, const ELoggingModes LogMode = ELoggingModes::eSyncMode, const ELoggingBufferSizes BufferSize = ELoggingBufferSizes::eMediumBuffer ) noexcept;

Initializes the internal logging system with the specified configuration.

Configures log output mode, verbosity level, and destinations. The log file will be created or appended using the provided path. Initialization must occur before any log operation.

LogFileNameAndPath
Full path and name of the log file.
bPrintDateTime
Defines whether date/time will be included in each log line.
bPrintToConsoleOutput
Enables log output to console (stdout).
bPrintToDebugOutput
Enables log output to debugger (OutputDebugString).
LogLevel
Verbosity level. See ELoggingLevel.
LogMode
Log operation mode (synchronous or asynchronous). See ELoggingModes.
BufferSize
Default fixed buffer size for formatting log messages. See ELoggingBufferSizes.
0 = Success. 1 = Log already initialized. 2 = Invalid file path or name. 3 = Failed to create or open the log file. 4 = Not licensed (see Bundle::UnlockBundle).
This function must be called only once during initialization. Subsequent calls without shutdown will be ignored.
function

LogTick

Ethereal::Logging#
void LogTick( void ) noexcept;

Processes pending log entries and performs flush (if in asynchronous mode).

Must be called periodically when using asynchronous logging with "post operation" mode to ensure buffered messages are written.

Mandatory only when using ELoggingModes::eAsyncPostOperation.
function

LogShutdown

Ethereal::Logging#
void LogShutdown( void ) noexcept;

Shuts down the logging system and releases associated resources.

Ensures that all buffered messages are written and that the log file is properly closed. Must be called during application shutdown.

After shutdown, the logging system is disabled until reinitialized via LogInitialize.
function

IsLogEnabled

Ethereal::Logging#
bool IsLogEnabled( void ) noexcept;

Retrieves the log initialization state.

Returns the log state: @true if enabled. @false if disabled.
function

GetLogLevelID

Ethereal::Logging#
ELoggingLevel GetLogLevelID( void ) noexcept;

Retrieves the log initialization level.

Returns the log level ID, ELoggingLevel.
function

GetDroppedLogCount

Ethereal::Logging#
ETL_UINT64 GetDroppedLogCount( void ) noexcept;

Number of messages that could not be written to the log file.

The log file is opened once by LogInitialize and kept open until LogShutdown. Every message is still flushed as soon as it is written, so a crash does not cost the lines already logged.

Even so, a write can fail for reasons outside this library: the disk fills up, the file is deleted or locked by another process, the volume goes away. When that happens the message is lost, and this counter is the only trace of it: the log cannot report a failure to write to the log.

A nonzero value means the log file is incomplete, and whatever it is used for (audit, diagnosis, support) is missing lines. Console and debug outputs are written before the file and are not affected.

The counter is cumulative and only reset by LogInitialize.

Count of messages dropped since the last initialization. Zero is the expected value.
struct

ILogHook

Ethereal::Logging#
C++
struct   ILogHook
{
    /// @brief    Writes into @p pOut (up to @p uCap bytes, no terminator) a text that goes
    ///            into the line before the message. Returns how many bytes were written
    ///            (0: none). If the tagged line does not fit the log buffer, it goes out
    ///            without the tag.
    virtual std::size_t Decorate( char * pOut, std::size_t uCap ) ETL_NOEXCEPT = 0;

    /// @brief    The finished line, exactly as it goes to the outputs.
    virtual void OnRecord( ELoggingTypes eType, std::string_view sLine ) ETL_NOEXCEPT = 0;

    virtual ~ILogHook() = default;
};

A hook for code that wants to tag or see every log line (the Telemetry bridge puts the current trace and span in it, and sends the line to export). The log does not know who is on the other side.

Both methods run on the thread that logged, before the line goes to the outputs (or to the queue, in the asynchronous modes). Neither may log (it would recurse) or take long: they are on the path of every line. With no hook set, the log writes exactly what it wrote before.

function

LogSetHook

Ethereal::Logging#
void LogSetHook( ILogHook * pHook ) noexcept;

Sets the hook (or, with null, removes it). One at a time. The object must stay alive while it is set.

function

LogPrintf

Ethereal::Logging#
void LogPrintf( const char * Text, ... ) noexcept;

Writes a simple message to the log with optional formatting.

Prepares the message using printf-style formatting and writes directly to the configured log. Log level checking is ignored and log type is Generic (eGeneric).

Text
C-string message with variadic parameters (printf style).
Use this function for generic messages where no specific type or log level is required.
function

LogPrintf

Ethereal::Logging#
void LogPrintf( const ELoggingTypes LogType, const char * Text, ... ) noexcept;

Writes a message to the log with a specific log type.

Allows classification of the message with a specific log type, such as error, warning, info, etc. Formatting follows printf style.

LogType
Log message type (e.g., eInfo, eWarning, eError). See ELoggingTypes.
Text
C-string message with variadic parameters.
Ideal for categorizing log messages logically.
function

LogPrintf

Ethereal::Logging#
void LogPrintf( const ELoggingLevel MinReqLogLevel, const ELoggingTypes LogType, const char * Text, ... ) noexcept;

Writes a message to the log with minimum required level and specified type.

The message will only be written if the configured log level is equal to or lower than the level specified during initialization. Provides greater control over what is recorded.

MinReqLogLevel
Minimum required log level for processing. See ELoggingLevel.
LogType
Log message type (e.g., eDebug, eError, eWarning). See ELoggingTypes.
Text
C-string message with variadic parameters.
Use this function for messages sensitive to the current log level. Recommended for production systems with active log filtering.
function

LogStdPrint

Ethereal::Logging#
template< typename... Args > void LogStdPrint( const char * Text, Args &&... args ) noexcept

Writes a simple message to the log with optional formatting.

Prepares the message using std::format-style formatting and writes directly to the configured log. Log level checking is ignored and log type is Generic (eGeneric).

Text/args
C/C++ formatted message with arguments to be substituted inside '{}' placeholders. ** Does not warn about formatting failures or invalid '{}' inputs.
Use this function for generic messages where there is no need to specify log type or level.
function

LogStdPrint

Ethereal::Logging#
template< typename... Args > void LogStdPrint( const ELoggingTypes LogType, const char * Text, Args &&... args ) noexcept

Writes a message to the log with a specific log type.

Allows classification of the message with a specific log type, such as error, warning, informational, etc. Formatting follows the std::format style.

LogType
Log message type (e.g., eInfo, eWarning, eError). See ELoggingTypes.
Text/args
C/C++ formatted message with arguments to be substituted inside '{}' placeholders. ** Does not warn about formatting failures or invalid '{}' inputs.
Ideal for categorizing log messages logically.
function

LogStdPrint

Ethereal::Logging#
template< typename... Args > void LogStdPrint( const ELoggingLevel MinReqLogLevel, const ELoggingTypes LogType, const char * Text, Args &&... args ) noexcept

Writes a message to the log with minimum required level and specified type.

The message will only be written if the system's configured log level is equal to or lower than the level specified during log initialization. Provides greater control over what is recorded.

MinReqLogLevel
Minimum required log level for processing. See ELoggingLevel.
LogType
Log message type (e.g., eDebug, eError, eWarning). See ELoggingTypes.
Text/args
C/C++ formatted message with arguments to be substituted inside '{}' placeholders. ** Does not warn about formatting failures or invalid '{}' inputs.
Use this function for messages sensitive to the current log level. Recommended for production systems with active log filtering.