20std::string LogLevelToString(
LogLevel level)
28 default:
return "UNKNOWN";
41 std::lock_guard<std::mutex> lock(mMutex);
47 if (!std::filesystem::exists(logFolderPath))
49 std::filesystem::create_directory(logFolderPath);
53 auto now = std::chrono::system_clock::now();
54 auto nowTimeT = std::chrono::system_clock::to_time_t(now);
58 localtime_s(&localTime, &nowTimeT);
60 localtime_r(&nowTimeT, &localTime);
63 std::ostringstream filename;
64 filename << logFolderPath.string() <<
"/"
66 << std::put_time(&localTime,
"%Y-%m-%d_%H-%M-%S")
69 mFile.open(filename.str(), std::ios::out | std::ios::trunc);
71 mCurrentLevel = ReadConfiguredLogLevel();
75 mFile <<
"===== Engine Log Started =====" << std::endl;
82 std::lock_guard<std::mutex> lock(mMutex);
86 mFile <<
"===== Engine Log Shutdown =====" << std::endl;
92LogLevel Logger::ReadConfiguredLogLevel()
97 if (confLogLevelStr == std::string{
"Debug" })
101 if (confLogLevelStr == std::string{
"Warning" })
105 if (confLogLevelStr == std::string{
"Error" })
110 return configuredLevel;
113void Logger::SetLogLevel(
LogLevel level)
115 std::lock_guard<std::mutex> lock(mMutex);
116 mCurrentLevel = level;
120 const std::string& message,
124 if (level < mCurrentLevel)
127 if (!mFile.is_open())
131 auto nowSystem = std::chrono::system_clock::now();
132 auto nowTimeT = std::chrono::system_clock::to_time_t(nowSystem);
133 auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
134 nowSystem.time_since_epoch()) % 1000;
138 localtime_s(&localTime, &nowTimeT);
140 localtime_r(&nowTimeT, &localTime);
143 std::ostringstream timestampStream;
144 timestampStream << std::put_time(&localTime,
"%Y-%m-%d %H:%M:%S")
145 <<
"." << std::setfill(
'0') << std::setw(3) << nowMs.count();
147 const auto threadId = std::this_thread::get_id();
149 std::lock_guard<std::mutex> lock(mMutex);
151 mFile <<
"[" << timestampStream.str() <<
"] "
152 <<
"[" << LogLevelToString(level) <<
"] "
153 <<
"[Thread " << threadId <<
"] "
155 <<
" (" << file <<
":" << line <<
")"
Singleton engine-wide logging system.
void Shutdown()
Finalizes logging system and closes the log file.
void Log(LogLevel level, const std::string &message, const char *file, int line)
Writes a formatted log message.
void Initialize(const std::string &appName)
Initializes logging system and creates a new log file.
static Logger & Get()
Returns singleton logger instance.
static std::filesystem::path GetLogsFolderPath()
Returns absolute path to Logs folder.
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
Engine-wide logging system for runtime diagnostics and performance tracking.
LogLevel
Defines severity levels for log messages.
@ Warning
Non-critical issues or unexpected states.
@ Info
General informational messages.
@ Error
Critical errors affecting functionality.
@ Debug
Detailed diagnostic information.
std::string logLevel
Logging verbosity level ("Error", "Warning", "Info", "Debug").