forked from metin2/server
Rewrote the log initialization functions, logs are now saved in rotating files, implemented configurable log levels
This commit is contained in:
@ -14,7 +14,11 @@ include_directories("include")
|
||||
# Create shared library
|
||||
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||
|
||||
# Find dependencies
|
||||
#
|
||||
# vcpkg dependencies
|
||||
#
|
||||
|
||||
# Boost
|
||||
find_package(Boost REQUIRED)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})
|
||||
|
@ -1,12 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
extern int log_init(void);
|
||||
extern void log_destroy(void);
|
||||
extern int log_init();
|
||||
extern void log_destroy();
|
||||
|
||||
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> bitvector<6F><72> ó<><C3B3><EFBFBD>ȴ<EFBFBD>)
|
||||
extern void log_set_level(unsigned int level);
|
||||
extern void log_unset_level(unsigned int level);
|
||||
|
||||
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ŭ <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4><C2B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
|
||||
extern void log_set_expiration_days(unsigned int days);
|
||||
extern int log_get_expiration_days(void);
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include <bsd/string.h>
|
||||
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
@ -1,39 +1,74 @@
|
||||
#define __LIBTHECORE__
|
||||
#include "stdafx.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
|
||||
#define SYSLOG_FILENAME "syslog.txt"
|
||||
#define SYSERR_FILENAME "syserr.txt"
|
||||
|
||||
unsigned int log_keep_days = 3;
|
||||
|
||||
|
||||
void log_set_level(unsigned int bit)
|
||||
int log_init()
|
||||
{
|
||||
}
|
||||
|
||||
void log_unset_level(unsigned int bit)
|
||||
{
|
||||
}
|
||||
// Replace the default logger with a placeholder in order to avoid a name clash
|
||||
spdlog::set_default_logger(spdlog::stderr_logger_mt("placeholder_name"));
|
||||
|
||||
void log_set_expiration_days(unsigned int days)
|
||||
{
|
||||
log_keep_days = days;
|
||||
}
|
||||
// Create the new logger
|
||||
std::vector<spdlog::sink_ptr> sinks;
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_st>("log/daily", 23, 59));
|
||||
auto combined_logger = std::make_shared<spdlog::logger>("", begin(sinks), end(sinks));
|
||||
|
||||
int log_get_expiration_days(void)
|
||||
{
|
||||
return log_keep_days;
|
||||
}
|
||||
//register it if you need to access it globally
|
||||
//spdlog::register_logger(combined_logger);
|
||||
|
||||
int log_init(void)
|
||||
{
|
||||
//spdlog::set_level(spdlog::level::debug);
|
||||
// Set the new logger as default
|
||||
spdlog::set_default_logger(combined_logger);
|
||||
|
||||
// Set flush period and default log level
|
||||
spdlog::flush_every(std::chrono::seconds(5));
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void log_destroy(void)
|
||||
void log_destroy()
|
||||
{
|
||||
|
||||
spdlog::shutdown();
|
||||
}
|
||||
|
||||
void log_set_level(unsigned int level)
|
||||
{
|
||||
spdlog::level::level_enum spdlog_level;
|
||||
|
||||
switch (level) {
|
||||
case SPDLOG_LEVEL_TRACE:
|
||||
spdlog_level = spdlog::level::trace;
|
||||
break;
|
||||
|
||||
case SPDLOG_LEVEL_DEBUG:
|
||||
spdlog_level = spdlog::level::debug;
|
||||
break;
|
||||
|
||||
case SPDLOG_LEVEL_INFO:
|
||||
spdlog_level = spdlog::level::info;
|
||||
break;
|
||||
|
||||
case SPDLOG_LEVEL_WARN:
|
||||
spdlog_level = spdlog::level::warn;
|
||||
break;
|
||||
|
||||
case SPDLOG_LEVEL_ERROR:
|
||||
spdlog_level = spdlog::level::err;
|
||||
break;
|
||||
|
||||
case SPDLOG_LEVEL_CRITICAL:
|
||||
spdlog_level = spdlog::level::critical;
|
||||
break;
|
||||
|
||||
case SPDLOG_LEVEL_OFF:
|
||||
spdlog_level = spdlog::level::off;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
spdlog::set_level(spdlog_level);
|
||||
}
|
@ -6,7 +6,6 @@
|
||||
*/
|
||||
#define __LIBTHECORE__
|
||||
#include "stdafx.h"
|
||||
#include "memory.h"
|
||||
|
||||
LPHEART thecore_heart = NULL;
|
||||
|
||||
@ -14,37 +13,6 @@ volatile int shutdowned = false;
|
||||
volatile int tics = 0;
|
||||
unsigned int thecore_profiler[NUM_PF];
|
||||
|
||||
static int pid_init(void)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
return true;
|
||||
#else
|
||||
FILE* fp;
|
||||
if ((fp = fopen("pid", "w")))
|
||||
{
|
||||
fprintf(fp, "%d", getpid());
|
||||
fclose(fp);
|
||||
SPDLOG_INFO("Start of pid: {}", getpid());
|
||||
}
|
||||
else
|
||||
{
|
||||
SPDLOG_ERROR("pid_init(): could not open file for writing. (filename: ./pid)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void pid_deinit(void)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
return;
|
||||
#else
|
||||
remove("./pid");
|
||||
SPDLOG_INFO("End of pid");
|
||||
#endif
|
||||
}
|
||||
|
||||
int thecore_init(int fps, HEARTFUNC heartbeat_func)
|
||||
{
|
||||
#if defined(__WIN32__) || defined(__linux__)
|
||||
@ -55,9 +23,6 @@ int thecore_init(int fps, HEARTFUNC heartbeat_func)
|
||||
#endif
|
||||
signal_setup();
|
||||
|
||||
if (!log_init() || !pid_init())
|
||||
return false;
|
||||
|
||||
thecore_heart = heart_new(1000000 / fps, heartbeat_func);
|
||||
return true;
|
||||
}
|
||||
@ -89,8 +54,6 @@ int thecore_idle(void)
|
||||
|
||||
void thecore_destroy(void)
|
||||
{
|
||||
pid_deinit();
|
||||
log_destroy();
|
||||
}
|
||||
|
||||
int thecore_pulse(void)
|
||||
|
Reference in New Issue
Block a user