Add a file for user warnings, userlog.txt. Until now, these types of warnings have either been cluttering info.txt or buried in log.txt where no sane user would want to look.
This commit is contained in:
+52
-17
@@ -55,8 +55,9 @@ static map<RString, RString> LogMaps;
|
||||
|
||||
#define LOG_PATH "/Logs/log.txt"
|
||||
#define INFO_PATH "/Logs/info.txt"
|
||||
#define USER_PATH "/Logs/userlog.txt"
|
||||
|
||||
static RageFile *g_fileLog, *g_fileInfo;
|
||||
static RageFile *g_fileLog, *g_fileInfo, *g_fileUserLog;
|
||||
|
||||
/* Mutex writes to the files. Writing to files is not thread-aware, and this is the
|
||||
* only place we write to the same file from multiple threads. */
|
||||
@@ -64,23 +65,29 @@ static RageMutex *g_Mutex;
|
||||
|
||||
/* staticlog gets info.txt
|
||||
* crashlog gets log.txt */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
/* If this is set, the message will also be written to info.txt. (info and warnings) */
|
||||
WRITE_TO_INFO = 0x01,
|
||||
|
||||
|
||||
/* If this is set, the message will also be written to userlog.txt. (user warnings only) */
|
||||
WRITE_TO_USER_LOG = 0x02,
|
||||
|
||||
/* Whether this line should be loud when written to log.txt (warnings). */
|
||||
WRITE_LOUD = 0x02
|
||||
WRITE_LOUD = 0x04
|
||||
};
|
||||
|
||||
RageLog::RageLog()
|
||||
{
|
||||
g_fileLog = new RageFile;
|
||||
g_fileInfo = new RageFile;
|
||||
g_fileUserLog = new RageFile;
|
||||
|
||||
g_Mutex = new RageMutex("Log");
|
||||
|
||||
m_bLogToDisk = false;
|
||||
m_bInfoToDisk = false;
|
||||
m_bUserLogToDisk = false;
|
||||
m_bFlush = false;
|
||||
m_bShowLogOutput = false;
|
||||
}
|
||||
@@ -102,14 +109,12 @@ RageLog::~RageLog()
|
||||
SetShowLogOutput( false );
|
||||
g_fileLog->Close();
|
||||
g_fileInfo->Close();
|
||||
g_fileUserLog->Close();
|
||||
|
||||
delete g_Mutex;
|
||||
g_Mutex = NULL;
|
||||
|
||||
delete g_fileLog;
|
||||
g_fileLog = NULL;
|
||||
delete g_fileInfo;
|
||||
g_fileInfo = NULL;
|
||||
SAFE_DELETE( g_Mutex );
|
||||
SAFE_DELETE( g_fileLog );
|
||||
SAFE_DELETE( g_fileInfo );
|
||||
SAFE_DELETE( g_fileUserLog );
|
||||
}
|
||||
|
||||
void RageLog::SetLogToDisk( bool b )
|
||||
@@ -148,6 +153,23 @@ void RageLog::SetInfoToDisk( bool b )
|
||||
fprintf( stderr, "Couldn't open %s: %s\n", INFO_PATH, g_fileInfo->GetError().c_str() );
|
||||
}
|
||||
|
||||
void RageLog::SetUserLogToDisk( bool b )
|
||||
{
|
||||
if( m_bUserLogToDisk == b )
|
||||
return;
|
||||
|
||||
m_bUserLogToDisk = b;
|
||||
|
||||
if( !m_bUserLogToDisk )
|
||||
{
|
||||
if( g_fileUserLog->IsOpen() )
|
||||
g_fileUserLog->Close();
|
||||
return;
|
||||
}
|
||||
if( !g_fileUserLog->Open(USER_PATH, RageFile::WRITE|RageFile::STREAMED) )
|
||||
fprintf( stderr, "Couldn't open %s: %s\n", USER_PATH, g_fileUserLog->GetError().c_str() );
|
||||
}
|
||||
|
||||
void RageLog::SetFlushing( bool b )
|
||||
{
|
||||
m_bFlush = b;
|
||||
@@ -173,19 +195,19 @@ void RageLog::SetShowLogOutput( bool show )
|
||||
#endif
|
||||
}
|
||||
|
||||
void RageLog::Trace( const char *fmt, ...)
|
||||
void RageLog::Trace( const char *fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
RString sBuff = vssprintf( fmt, va );
|
||||
va_end( va);
|
||||
va_end( va );
|
||||
|
||||
Write(0, sBuff );
|
||||
Write( 0, sBuff );
|
||||
}
|
||||
|
||||
/* Use this for more important information; it'll always be included
|
||||
* in crash dumps. */
|
||||
void RageLog::Info( const char *fmt, ...)
|
||||
void RageLog::Info( const char *fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
@@ -195,7 +217,7 @@ void RageLog::Info( const char *fmt, ...)
|
||||
Write( WRITE_TO_INFO, sBuff );
|
||||
}
|
||||
|
||||
void RageLog::Warn( const char *fmt, ...)
|
||||
void RageLog::Warn( const char *fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
@@ -205,6 +227,16 @@ void RageLog::Warn( const char *fmt, ...)
|
||||
Write( WRITE_TO_INFO | WRITE_LOUD, sBuff );
|
||||
}
|
||||
|
||||
void RageLog::UserLog( const char *fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
RString sBuf = vssprintf( fmt, va );
|
||||
va_end( va );
|
||||
|
||||
Write( WRITE_TO_USER_LOG, sBuf );
|
||||
}
|
||||
|
||||
void RageLog::Write( int where, const RString &line )
|
||||
{
|
||||
LockMut( *g_Mutex );
|
||||
@@ -232,8 +264,10 @@ void RageLog::Write( int where, const RString &line )
|
||||
printf("%s\n", str.c_str() );
|
||||
if( where & WRITE_TO_INFO )
|
||||
AddToInfo( str );
|
||||
if( m_bLogToDisk && where&WRITE_TO_INFO && g_fileInfo->IsOpen() )
|
||||
if( m_bLogToDisk && (where&WRITE_TO_INFO) && g_fileInfo->IsOpen() )
|
||||
g_fileInfo->PutLine( str );
|
||||
if( m_bUserLogToDisk && (where&WRITE_TO_USER_LOG) && g_fileUserLog->IsOpen() )
|
||||
g_fileUserLog->PutLine( str );
|
||||
|
||||
/* Add a timestamp to log.txt and RecentLogs, but not the rest of info.txt
|
||||
* and stdout. */
|
||||
@@ -259,6 +293,7 @@ void RageLog::Flush()
|
||||
{
|
||||
g_fileLog->Flush();
|
||||
g_fileInfo->Flush();
|
||||
g_fileUserLog->Flush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* RageLog - Manages logging. */
|
||||
|
||||
#ifndef RAGELOG_H
|
||||
#define RAGELOG_H
|
||||
#ifndef RAGE_LOG_H
|
||||
#define RAGE_LOG_H
|
||||
|
||||
class RageLog
|
||||
{
|
||||
@@ -9,9 +9,10 @@ public:
|
||||
RageLog();
|
||||
~RageLog();
|
||||
|
||||
void Trace( const char *fmt, ...) PRINTF(2,3);
|
||||
void Warn( const char *fmt, ...) PRINTF(2,3);
|
||||
void Info( const char *fmt, ...) PRINTF(2,3);
|
||||
void Trace( const char *fmt, ... ) PRINTF(2,3);
|
||||
void Warn( const char *fmt, ... ) PRINTF(2,3);
|
||||
void Info( const char *fmt, ... ) PRINTF(2,3);
|
||||
void UserLog( const char *fmt, ... ) PRINTF(2,3);
|
||||
void Flush();
|
||||
|
||||
void MapLog( const RString &key, const char *fmt, ... ) PRINTF(3,4);
|
||||
@@ -25,11 +26,13 @@ public:
|
||||
void SetShowLogOutput( bool show ); // enable or disable logging to stdout
|
||||
void SetLogToDisk( bool b ); // enable or disable logging to file
|
||||
void SetInfoToDisk( bool b ); // enable or disable logging info.txt to file
|
||||
void SetUserLogToDisk( bool b); // enable or disable logging user.txt to file
|
||||
void SetFlushing( bool b ); // enable or disable flushing
|
||||
|
||||
private:
|
||||
bool m_bLogToDisk;
|
||||
bool m_bInfoToDisk;
|
||||
bool m_bUserLogToDisk;
|
||||
bool m_bFlush;
|
||||
bool m_bShowLogOutput;
|
||||
void Write( int, const RString &str );
|
||||
|
||||
@@ -902,6 +902,7 @@ static void ApplyLogPreferences()
|
||||
LOG->SetShowLogOutput( PREFSMAN->m_bShowLogOutput );
|
||||
LOG->SetLogToDisk( PREFSMAN->m_bLogToDisk );
|
||||
LOG->SetInfoToDisk( true );
|
||||
LOG->SetUserLogToDisk( true );
|
||||
LOG->SetFlushing( PREFSMAN->m_bForceLogFlush );
|
||||
Checkpoints::LogCheckpoints( PREFSMAN->m_bLogCheckpoints );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user