forked from metin2/server
Applied changes on the db executable. Removed old logging functions. Various global changes.
This commit is contained in:
@ -18,3 +18,11 @@ add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||
find_package(Boost REQUIRED)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})
|
||||
|
||||
# fmt
|
||||
find_package(fmt CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt)
|
||||
|
||||
# spdlog
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog)
|
||||
|
@ -1,39 +1,12 @@
|
||||
#ifndef __INC_LIBTHECORE_LOG_H__
|
||||
#define __INC_LIBTHECORE_LOG_H__
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
extern int log_init(void);
|
||||
extern void log_destroy(void);
|
||||
extern void log_rotate(void);
|
||||
extern int log_init(void);
|
||||
extern void log_destroy(void);
|
||||
|
||||
// <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> ó<><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);
|
||||
|
||||
#ifndef __WIN32__
|
||||
extern void _sys_err(const char *func, int line, const char *format, ...);
|
||||
#else
|
||||
extern void _sys_err(const char *func, int line, const char *format, ...);
|
||||
#endif
|
||||
extern void sys_log_header(const char *header);
|
||||
extern void sys_log(unsigned int lv, const char *format, ...);
|
||||
extern void pt_log(const char *format, ...);
|
||||
|
||||
#ifndef __WIN32__
|
||||
#define sys_err(fmt, args...) _sys_err(__FUNCTION__, __LINE__, fmt, ##args)
|
||||
#else
|
||||
#define sys_err(fmt, ...) _sys_err(__FUNCTION__, __LINE__, fmt, __VA_ARGS__)
|
||||
#endif // __WIN32__
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __INC_LOG_H__
|
||||
// <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,6 +28,9 @@
|
||||
|
||||
#include <bsd/string.h>
|
||||
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
|
@ -42,7 +42,7 @@ using Random = effolkronium::random_static;
|
||||
|
||||
#define CREATE(result, type, number) do { \
|
||||
if (!((result) = (type *) calloc ((number), sizeof(type)))) { \
|
||||
sys_err("calloc failed [%d] %s", errno, strerror(errno)); \
|
||||
SPDLOG_CRITICAL("calloc failed [{}] {}", errno, strerror(errno)); \
|
||||
abort(); } } while(0)
|
||||
|
||||
#define RECREATE(result,type,number) do { \
|
||||
|
@ -71,7 +71,7 @@ bool safe_create(char** pdata, int number)
|
||||
{
|
||||
if (!((*pdata) = (char *) calloc (number, sizeof(char))))
|
||||
{
|
||||
sys_err("calloc failed [%d] %s", errno, strerror(errno));
|
||||
SPDLOG_ERROR("calloc failed [{}] {}", errno, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -111,7 +111,7 @@ LPBUFFER buffer_new(int size)
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> pool<6F><6C> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
buffer_pool_free();
|
||||
CREATE(buffer->mem_data, char, size);
|
||||
sys_err ("buffer pool free success.");
|
||||
SPDLOG_ERROR("buffer pool free success.");
|
||||
}
|
||||
}
|
||||
assert(buffer != NULL);
|
||||
@ -206,10 +206,10 @@ void buffer_read_proceed(LPBUFFER buffer, int length)
|
||||
return;
|
||||
|
||||
if (length < 0)
|
||||
sys_err("buffer_proceed: length argument lower than zero (length: %d)", length);
|
||||
SPDLOG_ERROR("buffer_proceed: length argument lower than zero (length: {})", length);
|
||||
else if (length > buffer->length)
|
||||
{
|
||||
sys_err("buffer_proceed: length argument bigger than buffer (length: %d, buffer: %d)", length, buffer->length);
|
||||
SPDLOG_ERROR("buffer_proceed: length argument bigger than buffer (length: {}, buffer: {})", length, buffer->length);
|
||||
length = buffer->length;
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ void buffer_read_proceed(LPBUFFER buffer, int length)
|
||||
// write_point <20><> pos <20><> <20>״<EFBFBD><D7B4><EFBFBD> <20>ΰ<EFBFBD> read_point <20><> <20><><EFBFBD><EFBFBD> <20><>Ų<EFBFBD><C5B2>.
|
||||
if (buffer->read_point + length - buffer->mem_data > buffer->mem_size)
|
||||
{
|
||||
sys_err("buffer_read_proceed: buffer overflow! length %d read_point %d", length, buffer->read_point - buffer->mem_data);
|
||||
SPDLOG_ERROR("buffer_read_proceed: buffer overflow! length {} read_point {}", length, buffer->read_point - buffer->mem_data);
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -254,7 +254,7 @@ void buffer_adjust_size(LPBUFFER& buffer, int add_size)
|
||||
if (buffer->mem_size >= buffer->write_point_pos + add_size)
|
||||
return;
|
||||
|
||||
sys_log(0, "buffer_adjust %d current %d/%d", add_size, buffer->length, buffer->mem_size);
|
||||
SPDLOG_TRACE("buffer_adjust {} current {}/{}", add_size, buffer->length, buffer->mem_size);
|
||||
buffer_realloc(buffer, buffer->mem_size + add_size);
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ void buffer_realloc(LPBUFFER& buffer, int length)
|
||||
return;
|
||||
|
||||
temp = buffer_new (length);
|
||||
sys_log(0, "reallocating buffer to %d, current %d", temp->mem_size, buffer->mem_size);
|
||||
SPDLOG_TRACE("reallocating buffer to {}, current {}", temp->mem_size, buffer->mem_size);
|
||||
memcpy(temp->mem_data, buffer->mem_data, buffer->mem_size);
|
||||
|
||||
read_point_pos = buffer->read_point - buffer->mem_data;
|
||||
|
@ -15,8 +15,8 @@ LPHEART heart_new(int opt_usec, HEARTFUNC func)
|
||||
|
||||
if (!func)
|
||||
{
|
||||
sys_err("no function defined");
|
||||
return NULL;
|
||||
SPDLOG_ERROR("no function defined");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CREATE(ht, HEART, 1);
|
||||
@ -80,14 +80,14 @@ int heart_idle(LPHEART ht)
|
||||
|
||||
if (missed_pulse <= 0)
|
||||
{
|
||||
sys_err("missed_pulse is not positive! (%d)", missed_pulse);
|
||||
missed_pulse = 1;
|
||||
SPDLOG_ERROR("missed_pulse is not positive! ({})", missed_pulse);
|
||||
missed_pulse = 1;
|
||||
}
|
||||
|
||||
if (missed_pulse > (30 * ht->passes_per_sec))
|
||||
{
|
||||
sys_err("losing %d seconds. (lag occured)", missed_pulse / ht->passes_per_sec);
|
||||
missed_pulse = 30 * ht->passes_per_sec;
|
||||
SPDLOG_ERROR("losing {} seconds. (lag occured)", missed_pulse / ht->passes_per_sec);
|
||||
missed_pulse = 30 * ht->passes_per_sec;
|
||||
}
|
||||
|
||||
return missed_pulse;
|
||||
|
@ -1,57 +1,19 @@
|
||||
/*
|
||||
* Filename: log.c
|
||||
* Description: local log file <20><><EFBFBD><EFBFBD>
|
||||
*
|
||||
* Author: <20><><EFBFBD><EFBFBD> aka. Cronan
|
||||
*/
|
||||
#define __LIBTHECORE__
|
||||
#include "stdafx.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
|
||||
#ifndef __WIN32__
|
||||
#define SYSLOG_FILENAME "syslog"
|
||||
#define SYSERR_FILENAME "syserr"
|
||||
#define PTS_FILENAME "PTS"
|
||||
#else
|
||||
#define SYSLOG_FILENAME "syslog.txt"
|
||||
#define SYSERR_FILENAME "syserr.txt"
|
||||
#define PTS_FILENAME "PTS.txt"
|
||||
#endif
|
||||
|
||||
typedef struct log_file_s * LPLOGFILE;
|
||||
typedef struct log_file_s LOGFILE;
|
||||
|
||||
struct log_file_s
|
||||
{
|
||||
char* filename;
|
||||
FILE* fp;
|
||||
|
||||
int last_hour;
|
||||
int last_day;
|
||||
};
|
||||
|
||||
LPLOGFILE log_file_sys = NULL;
|
||||
LPLOGFILE log_file_err = NULL;
|
||||
LPLOGFILE log_file_pt = NULL;
|
||||
static char log_dir[32] = { 0, };
|
||||
unsigned int log_keep_days = 3;
|
||||
|
||||
// Internal functions
|
||||
LPLOGFILE log_file_init(const char* filename, const char *openmode);
|
||||
void log_file_destroy(LPLOGFILE logfile);
|
||||
void log_file_rotate(LPLOGFILE logfile);
|
||||
void log_file_check(LPLOGFILE logfile);
|
||||
void log_file_set_dir(const char *dir);
|
||||
|
||||
static unsigned int log_level_bits = 7;
|
||||
|
||||
void log_set_level(unsigned int bit)
|
||||
{
|
||||
log_level_bits |= bit;
|
||||
}
|
||||
|
||||
void log_unset_level(unsigned int bit)
|
||||
{
|
||||
log_level_bits &= ~bit;
|
||||
}
|
||||
|
||||
void log_set_expiration_days(unsigned int days)
|
||||
@ -66,404 +28,12 @@ int log_get_expiration_days(void)
|
||||
|
||||
int log_init(void)
|
||||
{
|
||||
log_file_set_dir("./log");
|
||||
//spdlog::set_level(spdlog::level::debug);
|
||||
|
||||
do
|
||||
{
|
||||
log_file_sys = log_file_init(SYSLOG_FILENAME, "a+");
|
||||
if( NULL == log_file_sys ) break;
|
||||
|
||||
log_file_err = log_file_init(SYSERR_FILENAME, "a+");
|
||||
if( NULL == log_file_err ) break;
|
||||
|
||||
log_file_pt = log_file_init(PTS_FILENAME, "w");
|
||||
if( NULL == log_file_pt ) break;
|
||||
|
||||
return true;
|
||||
}
|
||||
while( false );
|
||||
|
||||
return false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void log_destroy(void)
|
||||
{
|
||||
log_file_destroy(log_file_sys);
|
||||
log_file_destroy(log_file_err);
|
||||
log_file_destroy(log_file_pt);
|
||||
|
||||
log_file_sys = NULL;
|
||||
log_file_err = NULL;
|
||||
log_file_pt = NULL;
|
||||
}
|
||||
|
||||
void log_rotate(void)
|
||||
{
|
||||
log_file_check(log_file_sys);
|
||||
log_file_check(log_file_err);
|
||||
log_file_check(log_file_pt);
|
||||
|
||||
log_file_rotate(log_file_sys);
|
||||
}
|
||||
|
||||
#ifndef __WIN32__
|
||||
void _sys_err(const char *func, int line, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
time_t ct = time(0);
|
||||
char *time_s = asctime(localtime(&ct));
|
||||
|
||||
struct timeval tv;
|
||||
int nMiliSec = 0;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
|
||||
|
||||
char buf[1024 + 2]; // \n<><6E> <20><><EFBFBD>̱<EFBFBD> <20><><EFBFBD><EFBFBD>..
|
||||
int len;
|
||||
|
||||
if (!log_file_err)
|
||||
return;
|
||||
|
||||
time_s[strlen(time_s) - 1] = '\0';
|
||||
len = snprintf(buf, 1024, "SYSERR: %-15.15s.%ld :: %s: ", time_s + 4, tv.tv_usec, func);
|
||||
buf[1025] = '\0';
|
||||
|
||||
if (len < 1024)
|
||||
{
|
||||
va_start(args, format);
|
||||
vsnprintf(buf + len, 1024 - len, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
strcat(buf, "\n");
|
||||
|
||||
// log_file_err <20><> <20><><EFBFBD><EFBFBD>
|
||||
fputs(buf, log_file_err->fp);
|
||||
fflush(log_file_err->fp);
|
||||
|
||||
// log_file_sys <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
fputs(buf, log_file_sys->fp);
|
||||
fflush(log_file_sys->fp);
|
||||
}
|
||||
#else
|
||||
void _sys_err(const char *func, int line, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
time_t ct = time(0);
|
||||
char *time_s = asctime(localtime(&ct));
|
||||
|
||||
char buf[1024 + 2]; // \n<><6E> <20><><EFBFBD>̱<EFBFBD> <20><><EFBFBD><EFBFBD>..
|
||||
int len;
|
||||
|
||||
if (!log_file_err)
|
||||
return;
|
||||
|
||||
time_s[strlen(time_s) - 1] = '\0';
|
||||
len = snprintf(buf, 1024, "SYSERR: %-15.15s :: %s: ", time_s + 4, func);
|
||||
buf[1025] = '\0';
|
||||
|
||||
if (len < 1024)
|
||||
{
|
||||
va_start(args, format);
|
||||
vsnprintf(buf + len, 1024 - len, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
strcat(buf, "\n");
|
||||
|
||||
// log_file_err <20><> <20><><EFBFBD><EFBFBD>
|
||||
fputs(buf, log_file_err->fp);
|
||||
fflush(log_file_err->fp);
|
||||
|
||||
// log_file_sys <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
fputs(buf, log_file_sys->fp);
|
||||
fflush(log_file_sys->fp);
|
||||
|
||||
fputs(buf, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
static char sys_log_header_string[33] = "";
|
||||
|
||||
void sys_log_header(const char *header)
|
||||
{
|
||||
strncpy(sys_log_header_string, header, 32);
|
||||
}
|
||||
|
||||
void sys_log(unsigned int bit, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
struct timeval tv;
|
||||
int nMiliSec = 0;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
if (bit != 0 && !(log_level_bits & bit))
|
||||
return;
|
||||
|
||||
if (log_file_sys)
|
||||
{
|
||||
time_t ct = time(0);
|
||||
char *time_s = asctime(localtime(&ct));
|
||||
|
||||
fprintf(log_file_sys->fp, sys_log_header_string);
|
||||
|
||||
time_s[strlen(time_s) - 1] = '\0';
|
||||
fprintf(log_file_sys->fp, "%-15.15s.%ld :: ", time_s + 4, tv.tv_usec );
|
||||
|
||||
va_start(args, format);
|
||||
vfprintf(log_file_sys->fp, format, args);
|
||||
va_end(args);
|
||||
|
||||
fputc('\n', log_file_sys->fp);
|
||||
fflush(log_file_sys->fp);
|
||||
}
|
||||
|
||||
#ifndef __WIN32__
|
||||
// log_level<65><6C> 1 <20>̻<EFBFBD><CCBB><EFBFBD> <20><><EFBFBD>쿡<EFBFBD><ECBFA1> <20><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD>찡 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> stdout<75><74><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
if (log_level_bits > 1)
|
||||
{
|
||||
#endif
|
||||
fprintf(stdout, sys_log_header_string);
|
||||
|
||||
va_start(args, format);
|
||||
vfprintf(stdout, format, args);
|
||||
va_end(args);
|
||||
|
||||
fputc('\n', stdout);
|
||||
fflush(stdout);
|
||||
#ifndef __WIN32__
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void pt_log(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (!log_file_pt)
|
||||
return;
|
||||
|
||||
va_start(args, format);
|
||||
vfprintf(log_file_pt->fp, format, args);
|
||||
va_end(args);
|
||||
|
||||
fputc('\n', log_file_pt->fp);
|
||||
fflush(log_file_pt->fp);
|
||||
}
|
||||
|
||||
LPLOGFILE log_file_init(const char * filename, const char * openmode)
|
||||
{
|
||||
LPLOGFILE logfile;
|
||||
FILE * fp;
|
||||
struct tm curr_tm;
|
||||
time_t time_s;
|
||||
|
||||
time_s = time(0);
|
||||
curr_tm = *localtime(&time_s);
|
||||
|
||||
fp = fopen(filename, openmode);
|
||||
|
||||
if (!fp)
|
||||
return NULL;
|
||||
|
||||
logfile = (LPLOGFILE) malloc(sizeof(LOGFILE));
|
||||
logfile->filename = strdup(filename);
|
||||
logfile->fp = fp;
|
||||
logfile->last_hour = curr_tm.tm_hour;
|
||||
logfile->last_day = curr_tm.tm_mday;
|
||||
|
||||
return (logfile);
|
||||
}
|
||||
|
||||
void log_file_destroy(LPLOGFILE logfile)
|
||||
{
|
||||
if (logfile == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (logfile->filename)
|
||||
{
|
||||
free(logfile->filename);
|
||||
logfile->filename = NULL;
|
||||
}
|
||||
|
||||
if (logfile->fp)
|
||||
{
|
||||
fclose(logfile->fp);
|
||||
logfile->fp = NULL;
|
||||
}
|
||||
|
||||
free(logfile);
|
||||
}
|
||||
|
||||
void log_file_check(LPLOGFILE logfile)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> <20>ٽ<EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
if (stat(logfile->filename, &sb) != 0 && errno == ENOENT)
|
||||
{
|
||||
fclose(logfile->fp);
|
||||
logfile->fp = fopen(logfile->filename, "a+");
|
||||
}
|
||||
}
|
||||
|
||||
void log_file_delete_old(const char *filename)
|
||||
{
|
||||
struct stat sb;
|
||||
int num1, num2;
|
||||
char buf[32];
|
||||
char system_cmd[512];
|
||||
struct tm new_tm;
|
||||
|
||||
if (stat(filename, &sb) == -1)
|
||||
{
|
||||
perror("log_file_delete_old: stat");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!S_ISDIR(sb.st_mode))
|
||||
return;
|
||||
|
||||
new_tm = *tm_calc(NULL, -log_keep_days);
|
||||
sprintf(buf, "%04d%02d%02d", new_tm.tm_year + 1900, new_tm.tm_mon + 1, new_tm.tm_mday);
|
||||
num1 = atoi(buf);
|
||||
#ifndef __WIN32__
|
||||
{
|
||||
struct dirent ** namelist;
|
||||
int n;
|
||||
|
||||
n = scandir(filename, &namelist, 0, alphasort);
|
||||
|
||||
if (n < 0)
|
||||
perror("scandir");
|
||||
else
|
||||
{
|
||||
char name[MAXNAMLEN+1];
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
strncpy(name, namelist[n]->d_name, 255);
|
||||
name[255] = '\0';
|
||||
|
||||
free(namelist[n]);
|
||||
|
||||
if (*name == '.')
|
||||
continue;
|
||||
|
||||
if (!isdigit(*name))
|
||||
continue;
|
||||
|
||||
num2 = atoi(name);
|
||||
|
||||
if (num2 <= num1)
|
||||
{
|
||||
snprintf(system_cmd, sizeof(system_cmd), "rm -rf %s/%s", filename, name);
|
||||
system(system_cmd);
|
||||
|
||||
sys_log(0, "%s: SYSTEM_CMD: %s", __FUNCTION__, system_cmd);
|
||||
fprintf(stderr, "%s: SYSTEM_CMD: %s %s:%d %s:%d\n", __FUNCTION__, system_cmd, buf, num1, name, num2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(namelist);
|
||||
}
|
||||
#else
|
||||
{
|
||||
WIN32_FIND_DATA fdata;
|
||||
HANDLE hFind;
|
||||
if ((hFind = FindFirstFile(filename, &fdata)) != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (!isdigit(*fdata.cFileName))
|
||||
continue;
|
||||
|
||||
num2 = atoi(fdata.cFileName);
|
||||
|
||||
if (num2 <= num1)
|
||||
{
|
||||
sprintf(system_cmd, "del %s\\%s", filename, fdata.cFileName);
|
||||
system(system_cmd);
|
||||
|
||||
sys_log(0, "SYSTEM_CMD: %s", system_cmd);
|
||||
}
|
||||
}
|
||||
while (FindNextFile(hFind, &fdata));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_file_rotate(LPLOGFILE logfile)
|
||||
{
|
||||
struct tm curr_tm;
|
||||
time_t time_s;
|
||||
char dir[256];
|
||||
char system_cmd[512];
|
||||
|
||||
time_s = time(0);
|
||||
curr_tm = *localtime(&time_s);
|
||||
|
||||
if (curr_tm.tm_mday != logfile->last_day)
|
||||
{
|
||||
struct tm new_tm;
|
||||
new_tm = *tm_calc(&curr_tm, -3);
|
||||
|
||||
#ifndef __WIN32__
|
||||
sprintf(system_cmd, "rm -rf %s/%04d%02d%02d", log_dir, new_tm.tm_year + 1900, new_tm.tm_mon + 1, new_tm.tm_mday);
|
||||
#else
|
||||
sprintf(system_cmd, "del %s\\%04d%02d%02d", log_dir, new_tm.tm_year + 1900, new_tm.tm_mon + 1, new_tm.tm_mday);
|
||||
#endif
|
||||
system(system_cmd);
|
||||
|
||||
sys_log(0, "SYSTEM_CMD: %s", system_cmd);
|
||||
|
||||
logfile->last_day = curr_tm.tm_mday;
|
||||
}
|
||||
|
||||
if (curr_tm.tm_hour != logfile->last_hour)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
snprintf(dir, sizeof(dir), "%s/%04d%02d%02d", log_dir, curr_tm.tm_year + 1900, curr_tm.tm_mon + 1, curr_tm.tm_mday);
|
||||
|
||||
if (stat(dir, &stat_buf) != 0 || S_ISDIR(stat_buf.st_mode))
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
CreateDirectory(dir, NULL);
|
||||
#else
|
||||
mkdir(dir, S_IRWXU);
|
||||
#endif
|
||||
}
|
||||
|
||||
sys_log(0, "SYSTEM: LOG ROTATE (%04d-%02d-%02d %d)",
|
||||
curr_tm.tm_year + 1900, curr_tm.tm_mon + 1, curr_tm.tm_mday, logfile->last_hour);
|
||||
|
||||
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ݰ<EFBFBD>
|
||||
fclose(logfile->fp);
|
||||
|
||||
// <20>ű<EFBFBD><C5B1><EFBFBD>.
|
||||
#ifndef __WIN32__
|
||||
snprintf(system_cmd, sizeof(system_cmd), "mv %s %s/%s.%02d", logfile->filename, dir, logfile->filename, logfile->last_hour);
|
||||
#else
|
||||
snprintf(system_cmd, sizeof(system_cmd), "move %s %s\\%s.%02d", logfile->filename, dir, logfile->filename, logfile->last_hour);
|
||||
#endif
|
||||
system(system_cmd);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
logfile->last_hour = curr_tm.tm_hour;
|
||||
|
||||
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٽ<EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
logfile->fp = fopen(logfile->filename, "a+");
|
||||
}
|
||||
}
|
||||
|
||||
void log_file_set_dir(const char *dir)
|
||||
{
|
||||
strcpy(log_dir, dir);
|
||||
log_file_delete_old(log_dir);
|
||||
}
|
||||
|
@ -24,12 +24,11 @@ static int pid_init(void)
|
||||
{
|
||||
fprintf(fp, "%d", getpid());
|
||||
fclose(fp);
|
||||
sys_err("\nStart of pid: %d\n", getpid());
|
||||
SPDLOG_INFO("Start of pid: {}", getpid());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("pid_init(): could not open file for writing. (filename: ./pid)");
|
||||
sys_err("\nError writing pid file\n");
|
||||
SPDLOG_ERROR("pid_init(): could not open file for writing. (filename: ./pid)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -42,7 +41,7 @@ static void pid_deinit(void)
|
||||
return;
|
||||
#else
|
||||
remove("./pid");
|
||||
sys_err("\nEnd of pid\n");
|
||||
SPDLOG_INFO("End of pid");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -215,11 +215,11 @@ void thecore_sleep(struct timeval* timeout)
|
||||
{
|
||||
if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, timeout) < 0)
|
||||
{
|
||||
if (errno != EINTR)
|
||||
{
|
||||
sys_err("select sleep %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
if (errno != EINTR)
|
||||
{
|
||||
SPDLOG_ERROR("select sleep {}", strerror(errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,8 +232,8 @@ void thecore_msleep(DWORD dwMillisecond)
|
||||
}
|
||||
|
||||
void core_dump_unix(const char *who, WORD line)
|
||||
{
|
||||
sys_err("*** Dumping Core %s:%d ***", who, line);
|
||||
{
|
||||
SPDLOG_CRITICAL("*** Dumping Core {}:{} ***", who, line);
|
||||
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
Reference in New Issue
Block a user