Nameless Engine
Loading...
Searching...
No Matches
ne::Logger Class Reference

#include <Logger.h>

Public Member Functions

 Logger (const Logger &)=delete
 
Loggeroperator= (const Logger &)=delete
 
void info (std::string_view sText, const std::source_location location=std::source_location::current()) const
 
void warn (std::string_view sText, const std::source_location location=std::source_location::current()) const
 
void error (std::string_view sText, const std::source_location location=std::source_location::current()) const
 
void flushToDisk ()
 
std::filesystem::path getDirectoryWithLogs () const
 

Static Public Member Functions

static Loggerget ()
 
static size_t getTotalWarningsProduced ()
 
static size_t getTotalErrorsProduced ()
 

Static Private Member Functions

static std::string getDateTime ()
 
static void removeOldestLogFiles (const std::filesystem::path &sLogDirectory)
 

Private Attributes

std::unique_ptr< spdlog::logger > pSpdLogger = nullptr
 
std::filesystem::path sLoggerWorkingDirectory
 

Static Private Attributes

static std::atomic< size_t > iTotalWarningsProduced {0}
 
static std::atomic< size_t > iTotalErrorsProduced {0}
 
static constexpr size_t iMaxLogFiles = 5
 
static const char * sLogFileExtension = ".log"
 

Detailed Description

Logs to file and console.

Member Function Documentation

◆ error()

void ne::Logger::error ( std::string_view  sText,
const std::source_location  location = std::source_location::current() 
) const

Add text to console and log file using "error" category. The text message will be appended with the file name and the line it was called from.

Remarks
Forces the log to be flushed on the disk.
Parameters
sTextText to write to log.
locationShould not be passed explicitly.

◆ flushToDisk()

void ne::Logger::flushToDisk ( )

Forces the log to be flushed to the disk.

Remarks
Note that you are not required to call this explicitly as the logger will automatically flush the log to the disk from time to time but you can also explicitly call this function when you need to make sure the current log is fully saved on the disk.

◆ get()

Logger & ne::Logger::get ( )
static

Returns a reference to the logger instance. If no instance was created yet, this function will create it and return a reference to it.

Returns
Reference to the logger instance.

◆ getDateTime()

std::string ne::Logger::getDateTime ( )
staticprivate

Returns current date and time in format "month.day_hour-minute-second".

Returns
Date and time string.

◆ getDirectoryWithLogs()

std::filesystem::path ne::Logger::getDirectoryWithLogs ( ) const

Returns the directory that contains all logs.

Returns
Directory for logs.

◆ getTotalErrorsProduced()

size_t ne::Logger::getTotalErrorsProduced ( )
static

Returns the total number of errors produced at this point.

Returns
Error count.

◆ getTotalWarningsProduced()

size_t ne::Logger::getTotalWarningsProduced ( )
static

Returns the total number of warnings produced at this point.

Returns
Warning count.

◆ info()

void ne::Logger::info ( std::string_view  sText,
const std::source_location  location = std::source_location::current() 
) const

Add text to console and log file using "info" category. The text message will be appended with the file name and the line it was called from.

Parameters
sTextText to write to log.
locationShould not be passed explicitly.

◆ removeOldestLogFiles()

void ne::Logger::removeOldestLogFiles ( const std::filesystem::path &  sLogDirectory)
staticprivate

Removes oldest log files if the number of log files exceed a specific limit.

Parameters
sLogDirectoryDirectory that contains log files.

◆ warn()

void ne::Logger::warn ( std::string_view  sText,
const std::source_location  location = std::source_location::current() 
) const

Add text to console and log file using "warning" category. The text message will be appended with the file name and the line it was called from.

Remarks
Forces the log to be flushed on the disk.
Parameters
sTextText to write to log.
locationShould not be passed explicitly.

Member Data Documentation

◆ iMaxLogFiles

constexpr size_t ne::Logger::iMaxLogFiles = 5
inlinestaticconstexprprivate

The maximum number of log files in the logger directory. If the logger directory contains this amount of log files, the oldest log file will be removed to create a new one.

◆ iTotalErrorsProduced

std::atomic<size_t> ne::Logger::iTotalErrorsProduced {0}
inlinestaticprivate

The total number of errors produced.

◆ iTotalWarningsProduced

std::atomic<size_t> ne::Logger::iTotalWarningsProduced {0}
inlinestaticprivate

The total number of warnings produced.

◆ pSpdLogger

std::unique_ptr<spdlog::logger> ne::Logger::pSpdLogger = nullptr
private

Spdlog logger.

◆ sLogFileExtension

const char* ne::Logger::sLogFileExtension = ".log"
inlinestaticprivate

Extension of the log files.

◆ sLoggerWorkingDirectory

std::filesystem::path ne::Logger::sLoggerWorkingDirectory
private

Directory that is used to create logs.


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