// IACore-OSS; The Core Library for All IA Open Source Projects // Copyright (C) 2025 IAS (ias@iasoft.dev) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include #include #include namespace IACore { Logger::ELogLevel Logger::s_logLevel{Logger::ELogLevel::WARN}; std::ofstream Logger::s_logFile{}; VOID Logger::Initialize() { } VOID Logger::Terminate() { if (s_logFile.is_open()) { s_logFile.flush(); s_logFile.close(); } } BOOL Logger::EnableLoggingToDisk(IN PCCHAR filePath) { if (s_logFile.is_open()) { s_logFile.flush(); s_logFile.close(); } s_logFile.open(filePath); return s_logFile.is_open(); } VOID Logger::SetLogLevel(IN ELogLevel logLevel) { s_logLevel = logLevel; } VOID Logger::FlushLogs() { std::cout.flush(); if (s_logFile) s_logFile.flush(); } VOID Logger::LogInternal(IN PCCHAR prefix, IN PCCHAR tag, IN String &&msg) { const auto outLine = std::format("[{:>8.3f}]: [{}]: {}", GetSecondsCount(), tag, msg); std::cout << prefix << outLine << "\033[39m\n"; if (s_logFile) { s_logFile.write(outLine.data(), outLine.size()); s_logFile.put('\n'); s_logFile.flush(); } } } // namespace IACore