Nameless Engine
|
#include <Logger.h>
Public Member Functions | |
Logger (const Logger &)=delete | |
Logger & | operator= (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 Logger & | get () |
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" |
Logs to file and console.
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.
sText | Text to write to log. |
location | Should not be passed explicitly. |
void ne::Logger::flushToDisk | ( | ) |
Forces the log to be flushed to the disk.
|
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.
|
staticprivate |
Returns current date and time in format "month.day_hour-minute-second".
std::filesystem::path ne::Logger::getDirectoryWithLogs | ( | ) | const |
Returns the directory that contains all logs.
|
static |
Returns the total number of errors produced at this point.
|
static |
Returns the total number of warnings produced at this point.
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.
sText | Text to write to log. |
location | Should not be passed explicitly. |
|
staticprivate |
Removes oldest log files if the number of log files exceed a specific limit.
sLogDirectory | Directory that contains log files. |
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.
sText | Text to write to log. |
location | Should not be passed explicitly. |
|
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.
|
inlinestaticprivate |
The total number of errors produced.
|
inlinestaticprivate |
The total number of warnings produced.
|
private |
Spdlog logger.
|
inlinestaticprivate |
Extension of the log files.
|
private |
Directory that is used to create logs.