From 2ae7862e849cac132a5e51b5b9a37ebe2e61f177 Mon Sep 17 00:00:00 2001 From: Cydh Ramdh Date: Tue, 30 Jun 2015 10:58:07 +0700 Subject: [PATCH] Console Message Log update * Added `console_msg_log` for char-server and login-server. * Added `console_log_filepath` to determines log filepath. * Default for map_athena.conf is `./log/map-msg_log.log`, removed the hardcoded filepath. * Default for char_athena.conf is `./log/char-msg_log.log`. * Default for login_athena.conf is `./log/login-msg_log.log`. Signed-off-by: Cydh Ramdh --- conf/char_athena.conf | 11 +++++++++++ conf/login_athena.conf | 11 +++++++++++ conf/map_athena.conf | 3 +++ src/char/char.c | 6 ++++++ src/common/showmsg.c | 3 ++- src/common/showmsg.h | 1 + src/login/login.c | 7 +++++++ src/map/map.c | 3 +++ 8 files changed, 44 insertions(+), 1 deletion(-) diff --git a/conf/char_athena.conf b/conf/char_athena.conf index 590a362f93..f0f9cb0f7f 100644 --- a/conf/char_athena.conf +++ b/conf/char_athena.conf @@ -51,6 +51,17 @@ char_port: 6121 //If redirected output contains escape sequences (color codes) stdout_with_ansisequence: no +//Makes server log selected message types to a file in the /log/ folder +//1: Log Warning Messages +//2: Log Error and SQL Error messages. +//4: Log Debug Messages +//Example: "console_msg_log: 7" logs all 3 kinds +//Messages logged by this overrides console_silent setting +console_msg_log: 0 + +// File path to store the console messages above +console_log_filepath: ./log/char-msg_log.log + //Makes server output more silent by ommitting certain types of messages: //1: Hide Information messages //2: Hide Status messages diff --git a/conf/login_athena.conf b/conf/login_athena.conf index 27f26e8f1f..8529a3e014 100644 --- a/conf/login_athena.conf +++ b/conf/login_athena.conf @@ -25,6 +25,17 @@ login_port: 6900 //If redirected output contains escape sequences (color codes) stdout_with_ansisequence: no +//Makes server log selected message types to a file in the /log/ folder +//1: Log Warning Messages +//2: Log Error and SQL Error messages. +//4: Log Debug Messages +//Example: "console_msg_log: 7" logs all 3 kinds +//Messages logged by this overrides console_silent setting +console_msg_log: 0 + +// File path to store the console messages above +console_log_filepath: ./log/login-msg_log.log + //Makes server output more silent by omitting certain types of messages: //1: Hide Information messages //2: Hide Status messages diff --git a/conf/map_athena.conf b/conf/map_athena.conf index de550e88fd..5df09c33b2 100644 --- a/conf/map_athena.conf +++ b/conf/map_athena.conf @@ -55,6 +55,9 @@ stdout_with_ansisequence: no //Messages logged by this overrides console_silent setting console_msg_log: 0 +// File path to store the console messages above +console_log_filepath: ./log/map-msg_log.log + //Makes server output more silent by omitting certain types of messages: //1: Hide Information messages //2: Hide Status messages diff --git a/src/char/char.c b/src/char/char.c index 966e5a268e..c0a0c1ec73 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2675,6 +2675,10 @@ bool char_config_read(const char* cfgName, bool normal){ msg_silent = atoi(w2); if( msg_silent ) /* only bother if its actually enabled */ ShowInfo("Console Silent Setting: %d\n", atoi(w2)); + } else if (strcmpi(w1, "console_msg_log") == 0) { + console_msg_log = atoi(w2); + } else if (strcmpi(w1, "console_log_filepath") == 0) { + safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath)); } else if(strcmpi(w1,"stdout_with_ansisequence")==0){ stdout_with_ansisequence = config_switch(w2); } else if (strcmpi(w1, "char_maintenance") == 0) { @@ -2896,10 +2900,12 @@ int do_init(int argc, char **argv) runflag = CHARSERVER_ST_STARTING; mapindex_init(); + // Init default value CHAR_CONF_NAME = "conf/char_athena.conf"; LAN_CONF_NAME = "conf/subnet_athena.conf"; SQL_CONF_NAME = "conf/inter_athena.conf"; MSG_CONF_NAME_EN = "conf/msg_conf/char_msg.conf"; + safestrncpy(console_log_filepath, "./log/char-msg_log.log", sizeof(console_log_filepath)); cli_get_options(argc,argv); diff --git a/src/common/showmsg.c b/src/common/showmsg.c index 8a374d9042..65781b73ee 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -48,6 +48,7 @@ int stdout_with_ansisequence = 0; int msg_silent = 0; //Specifies how silent the console is. int console_msg_log = 0;//[Ind] msg error logging +char console_log_filepath[32] = "./log/unknown.log"; /////////////////////////////////////////////////////////////////////////////// /// static/dynamic buffer for the messages @@ -687,7 +688,7 @@ int _vShowMessage(enum msg_type flag, const char *string, va_list ap) ( ( flag == MSG_ERROR || flag == MSG_SQL ) && console_msg_log&2 ) || ( flag == MSG_DEBUG && console_msg_log&4 ) ) {//[Ind] FILE *log = NULL; - if( (log = fopen(SERVER_TYPE == ATHENA_SERVER_MAP ? "./log/map-msg_log.log" : "./log/unknown.log","a+")) ) { + if( (log = fopen(console_log_filepath ? console_log_filepath : "./log/unknown.log","a+")) ) { char timestring[255]; time_t curtime; time(&curtime); diff --git a/src/common/showmsg.h b/src/common/showmsg.h index 262690b185..ef92218b59 100644 --- a/src/common/showmsg.h +++ b/src/common/showmsg.h @@ -70,6 +70,7 @@ extern int stdout_with_ansisequence; //If the color ansi sequences are to be used. [flaviojs] extern int msg_silent; //Specifies how silent the console is. [Skotlex] extern int console_msg_log; //Specifies what error messages to log. [Ind] +extern char console_log_filepath[32]; ///< Filepath to save console_msg_log. [Cydh] extern char timestamp_format[20]; //For displaying Timestamps [Skotlex] enum msg_type { diff --git a/src/login/login.c b/src/login/login.c index 71e4a1b015..ac981ab9a4 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -577,6 +577,10 @@ bool login_config_read(const char* cfgName, bool normal) { if( msg_silent ) /* only bother if we actually have this enabled */ ShowInfo("Console Silent Setting: %d\n", atoi(w2)); } + else if (strcmpi(w1, "console_msg_log") == 0) + console_msg_log = atoi(w2); + else if (strcmpi(w1, "console_log_filepath") == 0) + safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath)); else if(!strcmpi(w1, "log_login")) login_config.log_login = (bool)config_switch(w2); else if(!strcmpi(w1, "new_account")) @@ -808,6 +812,9 @@ void set_server_type(void) { int do_init(int argc, char** argv) { runflag = LOGINSERVER_ST_STARTING; + // Init default value + safestrncpy(console_log_filepath, "./log/login-msg_log.log", sizeof(console_log_filepath)); + // initialize engine accounts = account_db_sql(); diff --git a/src/map/map.c b/src/map/map.c index 88aa384828..daa5158564 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3650,6 +3650,8 @@ int map_config_read(char *cfgName) enable_grf = config_switch(w2); else if (strcmpi(w1, "console_msg_log") == 0) console_msg_log = atoi(w2);//[Ind] + else if (strcmpi(w1, "console_log_filepath") == 0) + safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath)); else if (strcmpi(w1, "import") == 0) map_config_read(w2); else @@ -4327,6 +4329,7 @@ int do_init(int argc, char *argv[]) ATCOMMAND_CONF_FILENAME = "conf/atcommand_athena.conf"; SCRIPT_CONF_NAME = "conf/script_athena.conf"; GRF_PATH_FILENAME = "conf/grf-files.txt"; + safestrncpy(console_log_filepath, "./log/map-msg_log.log", sizeof(console_log_filepath)); /* Multilanguage */ MSG_CONF_NAME_EN = "conf/msg_conf/map_msg.conf"; // English (default)