Browse Source

engine: ensure all data was written to stdout when exiting

pull/2/head
Alibek Omarov 3 years ago
parent
commit
18933e7981
  1. 77
      engine/common/sys_con.c

77
engine/common/sys_con.c

@ -97,6 +97,20 @@ int Sys_LogFileNo( void ) @@ -97,6 +97,20 @@ int Sys_LogFileNo( void )
return s_ld.logfileno;
}
static void Sys_FlushStdout( void )
{
// never printing anything to stdout on mobiles
#if !XASH_MOBILE_PLATFORM
fflush( stdout );
#endif
}
static void Sys_FlushLogfile( void )
{
if( s_ld.logfile )
fflush( s_ld.logfile );
}
void Sys_InitLog( void )
{
const char *mode;
@ -147,6 +161,8 @@ void Sys_CloseLog( void ) @@ -147,6 +161,8 @@ void Sys_CloseLog( void )
break;
}
Sys_FlushStdout(); // flush to stdout to ensure all data was written
if( s_ld.logfile )
{
fprintf( s_ld.logfile, "\n");
@ -160,33 +176,11 @@ void Sys_CloseLog( void ) @@ -160,33 +176,11 @@ void Sys_CloseLog( void )
}
}
void Sys_PrintLog( const char *pMsg )
static void Sys_PrintColorized( const char *logtime, const char *msg )
{
time_t crt_time;
const struct tm *crt_tm;
char logtime[32] = "";
static char lastchar;
time( &crt_time );
crt_tm = localtime( &crt_time );
#if XASH_ANDROID && !XASH_DEDICATED
__android_log_print( ANDROID_LOG_DEBUG, "Xash", "%s", pMsg );
#endif
#if TARGET_OS_IOS
void IOS_Log(const char*);
IOS_Log(pMsg);
#endif
if( !lastchar || lastchar == '\n')
strftime( logtime, sizeof( logtime ), "[%H:%M:%S] ", crt_tm ); //short time
#ifdef XASH_COLORIZE_CONSOLE
{
char colored[4096];
const char *msg = pMsg;
int len = 0;
while( *msg && ( len < 4090 ) )
{
static char q3ToAnsi[ 8 ] =
@ -222,14 +216,41 @@ void Sys_PrintLog( const char *pMsg ) @@ -222,14 +216,41 @@ void Sys_PrintLog( const char *pMsg )
colored[len++] = *msg++;
}
colored[len] = 0;
printf( "\033[34m%s\033[0m%s\033[0m", logtime, colored );
}
}
void Sys_PrintLog( const char *pMsg )
{
time_t crt_time;
const struct tm *crt_tm;
char logtime[32] = "";
static char lastchar;
time( &crt_time );
crt_tm = localtime( &crt_time );
// platform-specific output
#if XASH_ANDROID && !XASH_DEDICATED
__android_log_print( ANDROID_LOG_DEBUG, "Xash", "%s", pMsg );
#endif
#if TARGET_OS_IOS
void IOS_Log(const char*);
IOS_Log(pMsg);
#endif
if( !lastchar || lastchar == '\n')
strftime( logtime, sizeof( logtime ), "[%H:%M:%S] ", crt_tm ); //short time
// spew to stdout, except mobiles
#if !XASH_MOBILE_PLATFORM
#ifdef XASH_COLORIZE_CONSOLE
Sys_PrintColorized( logtime, pMsg );
#else
#if !XASH_ANDROID || XASH_DEDICATED
printf( "%s %s", logtime, pMsg );
fflush( stdout );
#endif
Sys_FlushStdout();
#endif
// save last char to detect when line was not ended
@ -242,7 +263,7 @@ void Sys_PrintLog( const char *pMsg ) @@ -242,7 +263,7 @@ void Sys_PrintLog( const char *pMsg )
strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S]", crt_tm ); //full time
fprintf( s_ld.logfile, "%s %s", logtime, pMsg );
fflush( s_ld.logfile );
Sys_FlushLogfile();
}
/*

Loading…
Cancel
Save