diff --git a/engine/common/host.c b/engine/common/host.c index 70cb51c5..b30063ff 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -140,7 +140,8 @@ static void Sys_PrintUsage( const char *exename ) "\nCommon options:\n" O("-dev [level] ", "set log verbosity 0-2") - O("-log ", "write log to \"engine.log\"") + O("-log [file name] ", "write log to \"engine.log\" or [file name] if specified") + O("-logtime ", "enable writing timestamps to the log file") O("-nowriteconfig ", "disable config save") O("-noch ", "disable crashhandler") #if XASH_WIN32 // !!!! diff --git a/engine/common/sys_con.c b/engine/common/sys_con.c index 624120e6..091b27a3 100644 --- a/engine/common/sys_con.c +++ b/engine/common/sys_con.c @@ -31,15 +31,14 @@ GNU General Public License for more details. #define XASH_COLORIZE_CONSOLE 0 #endif -typedef struct { - char title[64]; - qboolean log_active; - char log_path[MAX_SYSPATH]; - FILE *logfile; - int logfileno; -} LogData; - -static LogData s_ld; +static struct logdata_s { + char title[64]; + qboolean log_active; + qboolean log_time; + char log_path[MAX_SYSPATH]; + FILE *logfile; + int logfileno; +} s_ld; void Sys_DestroyConsole( void ) { @@ -78,14 +77,19 @@ static void Sys_FlushLogfile( void ) void Sys_InitLog( void ) { - const char *mode; + const char *mode; if( Sys_CheckParm( "-log" )) { + if( !Sys_GetParmFromCmdLine( "-log", s_ld.log_path )) + Q_strncpy( s_ld.log_path, "engine.log", sizeof( s_ld.log_path )); + + COM_DefaultExtension( s_ld.log_path, ".log", sizeof( s_ld.log_path )); s_ld.log_active = true; - Q_strncpy( s_ld.log_path, "engine.log", sizeof( s_ld.log_path )); } + s_ld.log_time = Sys_CheckParm( "-logtime" ); + if( host.change_game && host.type != HOST_DEDICATED ) mode = "a"; else mode = "w"; @@ -101,7 +105,7 @@ void Sys_InitLog( void ) if ( !s_ld.logfile ) { - Con_Reportf( S_ERROR "Sys_InitLog: can't create log file %s: %s\n", s_ld.log_path, strerror( errno )); + Con_Reportf( S_ERROR "%s: can't create log file %s: %s\n", __func__, s_ld.log_path, strerror( errno )); return; } @@ -295,17 +299,23 @@ void Sys_PrintLog( const char *pMsg ) // save last char to detect when line was not ended lastchar = len > 0 ? pMsg[len - 1] : 0; - if( !s_ld.logfile ) - return; - - if( print_time ) + // spew to engine.log + if( s_ld.logfile ) { - logtime_len = strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S] ", crt_tm ); //full time - logtime_len = Q_min( logtime_len, sizeof( logtime ) - 1 ); // just in case + if( s_ld.log_time && print_time ) + { + logtime_len = strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S] ", crt_tm ); //full time + logtime_len = Q_min( logtime_len, sizeof( logtime ) - 1 ); // just in case + } + else + { + logtime[0] = '\0'; + logtime_len = 0; + } + + Sys_PrintLogfile( s_ld.logfileno, logtime, logtime_len, pMsg, false ); + Sys_FlushLogfile(); } - - Sys_PrintLogfile( s_ld.logfileno, logtime, logtime_len, pMsg, false ); - Sys_FlushLogfile(); } /*