Преглед изворни кода

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 <cydh@pservero.com>

Cydh Ramdh пре 10 година
родитељ
комит
2ae7862e84
8 измењених фајлова са 44 додато и 1 уклоњено
  1. 11 0
      conf/char_athena.conf
  2. 11 0
      conf/login_athena.conf
  3. 3 0
      conf/map_athena.conf
  4. 6 0
      src/char/char.c
  5. 2 1
      src/common/showmsg.c
  6. 1 0
      src/common/showmsg.h
  7. 7 0
      src/login/login.c
  8. 3 0
      src/map/map.c

+ 11 - 0
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

+ 11 - 0
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

+ 3 - 0
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

+ 6 - 0
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);
 

+ 2 - 1
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);

+ 1 - 0
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 {

+ 7 - 0
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();
 

+ 3 - 0
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)