libnick 2024.9.2
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::Logging::Logger Class Reference

A logger of application messages. More...

#include <logger.h>

Public Member Functions

 Logger (LogLevel minimum=LogLevel::Debug)
 Constructs a Logger.
 
 Logger (const std::filesystem::path &path, LogLevel minimum=LogLevel::Debug, bool append=true)
 Constructs a Logger.
 
const std::filesystem::path & getPath () const
 Gets the path for the logs file.
 
void log (LogLevel level, const std::string &message, const std::source_location &source=std::source_location::current()) const
 Logs a message.
 

Detailed Description

A logger of application messages.

Constructor & Destructor Documentation

◆ Logger() [1/2]

Nickvision::Logging::Logger::Logger ( LogLevel minimum = LogLevel::Debug)

Constructs a Logger.

All messages are printed to standard outputs.

Parameters
minimumThe minimum supported LogLevel

◆ Logger() [2/2]

Nickvision::Logging::Logger::Logger ( const std::filesystem::path & path,
LogLevel minimum = LogLevel::Debug,
bool append = true )

Constructs a Logger.

All messages are saved to the provided file and printed to standard outputs.

Parameters
pathThe path to the log file
minimumThe minimum supported LogLevel
appendWhether or not to append to the file if it already exists
Exceptions
std::runtime_errorThrown if the unable to open the file

Member Function Documentation

◆ getPath()

const std::filesystem::path & Nickvision::Logging::Logger::getPath ( ) const

Gets the path for the logs file.

If the logger has no file attached, an empty path will be returned.

Returns
The path to the logs file

◆ log()

void Nickvision::Logging::Logger::log ( LogLevel level,
const std::string & message,
const std::source_location & source = std::source_location::current() ) const

Logs a message.

Parameters
levelLogLevel
messageThe message to log
sourceThe code location of the log message

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