engine: disable timestamps in log file by default, allow changing log file name with -log argument
This commit is contained in:
parent
51d11f8e86
commit
6529692244
2 changed files with 33 additions and 22 deletions
|
@ -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 // !!!!
|
||||
|
|
|
@ -31,15 +31,14 @@ GNU General Public License for more details.
|
|||
#define XASH_COLORIZE_CONSOLE 0
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
static struct logdata_s {
|
||||
char title[64];
|
||||
qboolean log_active;
|
||||
qboolean log_time;
|
||||
char log_path[MAX_SYSPATH];
|
||||
FILE *logfile;
|
||||
int logfileno;
|
||||
} LogData;
|
||||
|
||||
static LogData s_ld;
|
||||
} s_ld;
|
||||
|
||||
void Sys_DestroyConsole( void )
|
||||
{
|
||||
|
@ -82,10 +81,15 @@ void Sys_InitLog( void )
|
|||
|
||||
if( Sys_CheckParm( "-log" ))
|
||||
{
|
||||
s_ld.log_active = true;
|
||||
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;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue