diff --git a/2dlib/CMakeLists.txt b/2dlib/CMakeLists.txt index 38b84c8a..8577875d 100644 --- a/2dlib/CMakeLists.txt +++ b/2dlib/CMakeLists.txt @@ -15,9 +15,9 @@ set(CPPS add_library(2dlib STATIC ${HEADERS} ${CPPS}) target_link_libraries(2dlib PRIVATE cfile + logger mem misc - plog::plog ) target_include_directories(2dlib PUBLIC $:/DEBUG:FULL>) diff --git a/Descent3/sdlmain.cpp b/Descent3/sdlmain.cpp index e44a5db5..dca8161e 100644 --- a/Descent3/sdlmain.cpp +++ b/Descent3/sdlmain.cpp @@ -33,20 +33,9 @@ #include #endif -#ifdef WIN32 -#include -#include -#include "debug.h" -#endif - #include -// We use direct plog includes instead of log.h for logger instance initialization -#include -#include -#include #include "appdatabase.h" -#include "ddio.h" #include "application.h" #include "args.h" #include "d3_version.h" @@ -54,6 +43,7 @@ #include "descent.h" #include "dedicated_server.h" #include "init.h" +#include "log.h" #ifdef WIN32 #include "debug.h" @@ -216,38 +206,6 @@ int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event) { return (1); } -/** - * Initialize logger facility. - * @param log_level desired log level (for example, plog::debug) - * @param enable_filelog enable logging into Descent.log - * @param enable_win_console enable console windows for WIN32 (no-op for POSIX systems) - */ -void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console) { - std::filesystem::path log_file = "Descent3.log"; - static plog::ColorConsoleAppender consoleAppender; - static plog::RollingFileAppender fileAppender(log_file.u8string().c_str()); - -#ifdef WIN32 - if (enable_win_console) { - // Open console window - AllocConsole(); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - } -#endif - - plog::init(log_level, &consoleAppender); - if (enable_filelog) { - if (std::filesystem::is_regular_file(log_file)) { - // Delete old log - std::error_code ec; - std::filesystem::remove(log_file, ec); - plog::get()->addAppender(&fileAppender); - } - } -} - // --------------------------------------------------------------------------- // Main // creates all the OS objects and then runs Descent 3. diff --git a/bitmap/CMakeLists.txt b/bitmap/CMakeLists.txt index 531bb21a..12b05735 100644 --- a/bitmap/CMakeLists.txt +++ b/bitmap/CMakeLists.txt @@ -15,9 +15,9 @@ target_link_libraries(bitmap PRIVATE cfile ddebug ddio + logger mem misc - plog::plog stb ) target_include_directories(bitmap PUBLIC diff --git a/cfile/CMakeLists.txt b/cfile/CMakeLists.txt index a249fdcf..2deebbdc 100644 --- a/cfile/CMakeLists.txt +++ b/cfile/CMakeLists.txt @@ -11,9 +11,9 @@ set(CPPS add_library(cfile STATIC ${HEADERS} ${CPPS}) target_link_libraries(cfile PRIVATE ddio + logger mem misc - plog::plog ) target_include_directories(cfile PUBLIC $ +) diff --git a/logger/log.cpp b/logger/log.cpp new file mode 100644 index 00000000..7bc81075 --- /dev/null +++ b/logger/log.cpp @@ -0,0 +1,56 @@ +/* + * Descent 3 + * Copyright (C) 2024 Descent Developers + * + * 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 +#include + +#ifdef WIN32 +#include +#include +#include "debug.h" +#endif + +#include "log.h" + +void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console) { + std::filesystem::path log_file = "Descent3.log"; + static plog::ColorConsoleAppender consoleAppender; + static plog::RollingFileAppender fileAppender(log_file.u8string().c_str()); + +#ifdef WIN32 + if (enable_win_console) { + // Open console window + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + } +#endif + + plog::init(log_level, &consoleAppender); + if (enable_filelog) { + if (std::filesystem::is_regular_file(log_file)) { + // Delete old log + std::error_code ec; + std::filesystem::remove(log_file, ec); + } + plog::get()->addAppender(&fileAppender); + } +} \ No newline at end of file diff --git a/lib/log.h b/logger/log.h similarity index 79% rename from lib/log.h rename to logger/log.h index 53a278f2..0d5b6cfc 100644 --- a/lib/log.h +++ b/logger/log.h @@ -32,3 +32,11 @@ In case of swapping to another solution here should be redefined following macro #define LOG_FATAL PLOG(plog::fatal) */ + +/** + * Initialize logger facility. + * @param log_level desired log level (for example, plog::debug) + * @param enable_filelog enable logging into Descent.log + * @param enable_win_console enable console windows for WIN32 (no-op for POSIX systems) + */ +void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console); diff --git a/manage/CMakeLists.txt b/manage/CMakeLists.txt index 8fd38cdb..262309fa 100644 --- a/manage/CMakeLists.txt +++ b/manage/CMakeLists.txt @@ -25,10 +25,10 @@ add_library(manage STATIC ${HEADERS} ${CPPS}) target_link_libraries(manage PRIVATE cfile ddio + logger mem misc model sndlib stream_audio - plog::plog ) diff --git a/mem/CMakeLists.txt b/mem/CMakeLists.txt index 8be9a709..7e72ae84 100644 --- a/mem/CMakeLists.txt +++ b/mem/CMakeLists.txt @@ -6,8 +6,8 @@ target_compile_definitions(mem PUBLIC $<$:MEM_USE_RTL> ) target_link_libraries(mem PRIVATE + logger misc - plog::plog ) target_include_directories(mem PUBLIC $handle = dlopen(modfilename.u8string().c_str(), f); if (!handle->handle) { - mprintf(0, "Module Load Err: %s\n", dlerror()); + LOG_ERROR.printf("Module Load Err: %s", dlerror()); ModLastError = MODERR_MODNOTFOUND; return false; } diff --git a/music/CMakeLists.txt b/music/CMakeLists.txt index 154ffa3b..0b82370c 100644 --- a/music/CMakeLists.txt +++ b/music/CMakeLists.txt @@ -12,11 +12,11 @@ target_link_libraries(music AudioEncode cfile ddio + logger mem misc sndlib stream_audio - plog::plog ) target_include_directories(music PUBLIC $