Cbeam
Loading...
Searching...
No Matches
cbeam::logging::log Class Reference

The log class provides basic file-based logging functionality. More...

#include <logging_impl.hpp>

Public Member Functions

 log (const std::filesystem::path &log_path)
 Constructs a log object that manages logging to a file.
 
 ~log () noexcept
 Destructor writes a final footer line before the log object is destroyed.
 
void append (const std::wstring &str) noexcept
 Appends a wide-string message to the log, along with thread and timestamp information.
 
void append (const std::string &str) noexcept
 Appends a narrow-string message to the log (converted internally to wide-string).
 

Detailed Description

The log class provides basic file-based logging functionality.

It creates or overwrites a log file at a specified path, writes log entries with timestamps and thread information, and ensures thread safety via a mutex.

Constructor & Destructor Documentation

◆ log()

cbeam::logging::log::log ( const std::filesystem::path & log_path)
inlineexplicit

Constructs a log object that manages logging to a file.

The constructor attempts to create parent directories, remove any existing log file, and then writes an initial header line.

Parameters
log_pathThe filesystem path to the log file.

◆ ~log()

cbeam::logging::log::~log ( )
inlinenoexcept

Destructor writes a final footer line before the log object is destroyed.

Also locks the mutex to ensure no other threads are writing at the same time.

Member Function Documentation

◆ append() [1/2]

void cbeam::logging::log::append ( const std::string & str)
inlinenoexcept

Appends a narrow-string message to the log (converted internally to wide-string).

Parameters
strThe narrow string message to be logged.

◆ append() [2/2]

void cbeam::logging::log::append ( const std::wstring & str)
inlinenoexcept

Appends a wide-string message to the log, along with thread and timestamp information.

This method attempts a non-blocking lock first for performance, falling back to a blocking lock if needed.

Parameters
strThe wide string message to be logged.

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