// MassBuilderSaveTool // Copyright (C) 2021-2024 Guillaume Jacquemin // // 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 #ifndef SAVETOOL_DEBUG_BUILD #include #include #include #endif #include #include "Logger.h" using Containers::Array; using Utility::Debug; using Utility::Warning; using Utility::Error; Logger& Logger::instance() { static Logger logger; return logger; } void Logger::initialise() { #ifndef SAVETOOL_DEBUG_BUILD auto exe_path = Utility::Path::split(*Utility::Path::executableLocation()).first(); _logFile.open(Utility::Path::join(exe_path, "SaveToolLog.txt").cbegin(), std::ios::trunc); _logFile << "In case you encounter a bug:\n" << "1. Do not run the Save Tool again, as this log will be cleared.\n" << "2. Go to either the official Sekai Project Discord guild, or the community M.A.S.S. Builder one.\n" << "3. Mention me (@williamjcm) to get my attention, with a description of the bug.\n" " Please include as many details as possible, I don't want to play \"20 questions\", and neither do you.\n" << "4. Send me this file _when I ask for it_, preferably in DMs.\n" << std::endl; #endif } void Logger::indent() { _indentLevel++; } void Logger::unindent() { if(_indentLevel > 0) { _indentLevel--; } } void Logger::log(EntryType type, StringView location, StringView message) { Debug d{ #ifdef SAVETOOL_DEBUG_BUILD &std::cout #else &_logFile #endif }; switch(type) { case EntryType::Info: d << "[ INFO]"_s; break; case EntryType::Warning: d << "[WARNING]"_s; break; case EntryType::Error: d << "[ ERROR]"_s; break; } d << "["_s << Debug::nospace << location << Debug::nospace << "]"_s; for(auto i = 0u; i < _indentLevel; i++) { d << Debug::nospace << " "_s << Debug::nospace; } d << ((message.back() == '\n') ? message.exceptSuffix(1) : message); } void Logger::lockMutex() { _logMutex.lock(); } void Logger::unlockMutex() { _logMutex.unlock(); } Logger& logger() { return Logger::instance(); }