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"
|
"\nCommon options:\n"
|
||||||
O("-dev [level] ", "set log verbosity 0-2")
|
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("-nowriteconfig ", "disable config save")
|
||||||
O("-noch ", "disable crashhandler")
|
O("-noch ", "disable crashhandler")
|
||||||
#if XASH_WIN32 // !!!!
|
#if XASH_WIN32 // !!!!
|
||||||
|
|
|
@ -31,15 +31,14 @@ GNU General Public License for more details.
|
||||||
#define XASH_COLORIZE_CONSOLE 0
|
#define XASH_COLORIZE_CONSOLE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
static struct logdata_s {
|
||||||
char title[64];
|
char title[64];
|
||||||
qboolean log_active;
|
qboolean log_active;
|
||||||
char log_path[MAX_SYSPATH];
|
qboolean log_time;
|
||||||
FILE *logfile;
|
char log_path[MAX_SYSPATH];
|
||||||
int logfileno;
|
FILE *logfile;
|
||||||
} LogData;
|
int logfileno;
|
||||||
|
} s_ld;
|
||||||
static LogData s_ld;
|
|
||||||
|
|
||||||
void Sys_DestroyConsole( void )
|
void Sys_DestroyConsole( void )
|
||||||
{
|
{
|
||||||
|
@ -78,14 +77,19 @@ static void Sys_FlushLogfile( void )
|
||||||
|
|
||||||
void Sys_InitLog( void )
|
void Sys_InitLog( void )
|
||||||
{
|
{
|
||||||
const char *mode;
|
const char *mode;
|
||||||
|
|
||||||
if( Sys_CheckParm( "-log" ))
|
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;
|
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 )
|
if( host.change_game && host.type != HOST_DEDICATED )
|
||||||
mode = "a";
|
mode = "a";
|
||||||
else mode = "w";
|
else mode = "w";
|
||||||
|
@ -101,7 +105,7 @@ void Sys_InitLog( void )
|
||||||
|
|
||||||
if ( !s_ld.logfile )
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,17 +299,23 @@ void Sys_PrintLog( const char *pMsg )
|
||||||
// save last char to detect when line was not ended
|
// save last char to detect when line was not ended
|
||||||
lastchar = len > 0 ? pMsg[len - 1] : 0;
|
lastchar = len > 0 ? pMsg[len - 1] : 0;
|
||||||
|
|
||||||
if( !s_ld.logfile )
|
// spew to engine.log
|
||||||
return;
|
if( s_ld.logfile )
|
||||||
|
|
||||||
if( print_time )
|
|
||||||
{
|
{
|
||||||
logtime_len = strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S] ", crt_tm ); //full time
|
if( s_ld.log_time && print_time )
|
||||||
logtime_len = Q_min( logtime_len, sizeof( logtime ) - 1 ); // just in case
|
{
|
||||||
}
|
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_PrintLogfile( s_ld.logfileno, logtime, logtime_len, pMsg, false );
|
||||||
Sys_FlushLogfile();
|
Sys_FlushLogfile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue