Nameless Engine
Loading...
Searching...
No Matches
Logger.h
1#pragma once
2
3// Standard.
4#include <memory>
5#include <filesystem>
6#include <source_location>
7
8// External.
9#include "spdlog/spdlog.h"
10
11namespace ne {
15 class Logger {
16 public:
17 Logger(const Logger&) = delete;
18 Logger& operator=(const Logger&) = delete;
19 ~Logger();
20
28 static Logger& get();
29
35 static size_t getTotalWarningsProduced();
36
42 static size_t getTotalErrorsProduced();
43
51 void info(
52 std::string_view sText,
53 const std::source_location location = std::source_location::current()) const; // NOLINT
54
64 void warn(
65 std::string_view sText,
66 const std::source_location location = std::source_location::current()) const; // NOLINT
67
77 void error(
78 std::string_view sText,
79 const std::source_location location = std::source_location::current()) const; // NOLINT
80
89 void flushToDisk();
90
96 std::filesystem::path getDirectoryWithLogs() const;
97
98 private:
99 Logger();
100
106 static std::string getDateTime();
107
113 static void removeOldestLogFiles(const std::filesystem::path& sLogDirectory);
114
118 std::unique_ptr<spdlog::logger> pSpdLogger = nullptr;
119
123 std::filesystem::path sLoggerWorkingDirectory;
124
126 inline static std::atomic<size_t> iTotalWarningsProduced{0};
127
129 inline static std::atomic<size_t> iTotalErrorsProduced{0};
130
136 inline static constexpr size_t iMaxLogFiles = 5;
137
139 inline static const char* sLogFileExtension = ".log";
140 };
141} // namespace ne
Definition: Logger.h:15
static size_t getTotalErrorsProduced()
Definition: Logger.cpp:48
void info(std::string_view sText, const std::source_location location=std::source_location::current()) const
Definition: Logger.cpp:50
static std::string getDateTime()
Definition: Logger.cpp:124
std::filesystem::path sLoggerWorkingDirectory
Definition: Logger.h:123
std::filesystem::path getDirectoryWithLogs() const
Definition: Logger.cpp:90
std::unique_ptr< spdlog::logger > pSpdLogger
Definition: Logger.h:118
static std::atomic< size_t > iTotalErrorsProduced
Definition: Logger.h:129
void error(std::string_view sText, const std::source_location location=std::source_location::current()) const
Definition: Logger.cpp:75
static std::atomic< size_t > iTotalWarningsProduced
Definition: Logger.h:126
static const char * sLogFileExtension
Definition: Logger.h:139
static size_t getTotalWarningsProduced()
Definition: Logger.cpp:46
static Logger & get()
Definition: Logger.cpp:41
static constexpr size_t iMaxLogFiles
Definition: Logger.h:136
static void removeOldestLogFiles(const std::filesystem::path &sLogDirectory)
Definition: Logger.cpp:142
void flushToDisk()
Definition: Logger.cpp:88
void warn(std::string_view sText, const std::source_location location=std::source_location::current()) const
Definition: Logger.cpp:62