Rewrote the log initialization functions, logs are now saved in rotating files, implemented configurable log levels

This commit is contained in:
2024-03-03 18:51:51 +02:00
parent feac4c0598
commit a7f4e4e54d
11 changed files with 95 additions and 108 deletions

View File

@ -3,13 +3,20 @@ cmake_minimum_required(VERSION 3.8)
project(game CXX)
file(GLOB_RECURSE sources
src/*.cpp src/*.h
src/*.cpp src/*.h
)
# Add the src directory to the include path
include_directories(src)
add_executable(${PROJECT_NAME} ${sources})
# Set the default log level based on the build type
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "This is a debug build. Log level will be set to 'trace' for target '${PROJECT_NAME}'.")
target_compile_definitions(${PROJECT_NAME} PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
endif()
# Find dependencies
#
@ -43,10 +50,6 @@ endif (LZO_FOUND)
find_package(effolkronium_random CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} effolkronium_random)
# fmt
find_package(fmt CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} fmt::fmt)
#
# System-provided dependencies
#

View File

@ -663,10 +663,6 @@ void config_init(const string& st_localeServiceName)
}
// END_SKILL_POWER_BY_LEVEL
// LOG_KEEP_DAYS_EXTEND
log_set_expiration_days(2);
// END_OF_LOG_KEEP_DAYS_EXTEND
while (fgets(buf, 256, fp))
{
parse_token(buf, token_string, value_string);
@ -692,11 +688,11 @@ void config_init(const string& st_localeServiceName)
continue;
}
TOKEN("log_keep_days")
TOKEN("log_level")
{
int i = 0;
str_to_number(i, value_string);
log_set_expiration_days(std::clamp(i, 1, 90));
log_set_level(std::clamp(i, SPDLOG_LEVEL_TRACE, SPDLOG_LEVEL_OFF));
continue;
}

View File

@ -332,6 +332,7 @@ int main(int argc, char **argv)
ilInit(); // DevIL Initialize
WriteVersion();
log_init();
SECTREE_MANAGER sectree_manager;
CHARACTER_MANAGER char_manager;
@ -486,6 +487,7 @@ int main(int argc, char **argv)
trafficProfiler.Flush();
destroy();
log_destroy();
#ifdef DEBUG_ALLOC
DebugAllocator::StaticTearDown();
@ -499,7 +501,6 @@ void usage()
printf("Option list\n"
"-p <port> : bind port number (port must be over 1024)\n"
"-l <level> : sets log level\n"
"-v : log to stdout\n"
"-r : do not load regen tables\n"
"-t : traffic proflie on\n");
}
@ -508,15 +509,13 @@ int start(int argc, char **argv)
{
std::string st_localeServiceName;
bool bVerbose = false;
//_malloc_options = "A";
#if defined(__FreeBSD__) && defined(DEBUG_ALLOC)
_malloc_message = WriteMallocMessage;
#endif
int ch;
while ((ch = getopt(argc, argv, "n:p:verl:tI:")) != -1)
while ((ch = getopt(argc, argv, "n:p:erl:tI:")) != -1)
{
char* ep = NULL;
@ -556,10 +555,6 @@ int start(int argc, char **argv)
break;
// END_OF_LOCALE_SERVICE
case 'v': // verbose
bVerbose = true;
break;
case 'r':
g_bNoRegen = true;
break;
@ -588,11 +583,6 @@ int start(int argc, char **argv)
config_init(st_localeServiceName);
// END_OF_LOCALE_SERVICE
#ifdef __WIN32__
// In Windows dev mode, "verbose" option is [on] by default.
bVerbose = true;
#endif
bool is_thecore_initialized = thecore_init(25, heartbeat);
if (!is_thecore_initialized)

View File

@ -41,7 +41,7 @@ EVENTFUNC(regen_mob_event)
int iMapIndex = info->dwMapIndex;
char filename[128];
char filename[256];
std::string szFilename(GetSungziMapPath());