better log control for test set

This commit is contained in:
Glenn Maynard
2004-03-04 04:27:55 +00:00
parent 64842367b0
commit d3c0228a5d
3 changed files with 66 additions and 33 deletions
+35 -33
View File
@@ -19,7 +19,6 @@
#include "RageFile.h"
#include "RageThreads.h"
#include <time.h>
#include "ProductInfo.h"
#if defined(_WINDOWS)
#include "windows.h"
#endif
@@ -67,10 +66,8 @@ RageLog* LOG; // global and accessable from anywhere in the program
* map/unmap, using any mechanism to generate unique IDs. */
map<CString, CString> LogMaps;
// constants
/* We need to use SYS_BASE_PATH here, because this doesn't go through RageFile. */
#define LOG_PATH SYS_BASE_PATH "log.txt"
#define INFO_PATH SYS_BASE_PATH "info.txt"
#define LOG_PATH "log.txt"
#define INFO_PATH "info.txt"
static RageFile *g_fileLog, *g_fileInfo;
@@ -78,11 +75,6 @@ static RageFile *g_fileLog, *g_fileInfo;
* only place we write to the same file from multiple threads. */
RageMutex *g_Mutex;
#if defined(HAVE_VERSION_INFO)
extern unsigned long version_num;
extern const char *version_time;
#endif
/* staticlog gets info.txt
* crashlog gets log.txt */
enum {
@@ -101,7 +93,8 @@ RageLog::RageLog()
g_Mutex = new RageMutex;
m_bLogToDisk = true;
m_bLogToDisk = false;
m_bInfoToDisk = false;
m_bFlush = false;
m_bTimestamping = false;
m_bShowLogOutput = false;
@@ -109,28 +102,6 @@ RageLog::RageLog()
// delete old log files
remove( LOG_PATH );
remove( INFO_PATH );
// Open log file and leave it open.
if( !g_fileLog->Open( LOG_PATH, RageFile::WRITE|RageFile::STREAMED ) )
fprintf( stderr, "Couldn't open %s: %s\n", LOG_PATH, g_fileLog->GetError().c_str() );
if( !g_fileInfo->Open( INFO_PATH, RageFile::WRITE|RageFile::STREAMED ) )
fprintf( stderr, "Couldn't open %s: %s\n", INFO_PATH, g_fileInfo->GetError().c_str() );
this->Info( PRODUCT_NAME_VER );
#if defined(HAVE_VERSION_INFO)
this->Info( "Compiled %s (build %lu)", version_time, version_num );
#endif
time_t cur_time;
time(&cur_time);
struct tm now;
localtime_r( &cur_time, &now );
this->Info( "Log starting %.4d-%.2d-%.2d %.2d:%.2d:%.2d",
1900+now.tm_year, now.tm_mon+1, now.tm_mday, now.tm_hour+1, now.tm_min, now.tm_sec );
this->Trace( " " );
}
RageLog::~RageLog()
@@ -162,7 +133,38 @@ RageLog::~RageLog()
void RageLog::SetLogToDisk( bool b )
{
if( m_bLogToDisk == b )
return;
m_bLogToDisk = b;
if( !m_bLogToDisk )
{
if( g_fileLog->IsOpen() )
g_fileLog->Close();
return;
}
if( !g_fileLog->Open( LOG_PATH, RageFile::WRITE|RageFile::STREAMED ) )
fprintf( stderr, "Couldn't open %s: %s\n", LOG_PATH, g_fileLog->GetError().c_str() );
}
void RageLog::SetInfoToDisk( bool b )
{
if( m_bInfoToDisk == b )
return;
m_bInfoToDisk = b;
if( !m_bInfoToDisk )
{
if( g_fileInfo->IsOpen() )
g_fileInfo->Close();
return;
}
if( !g_fileInfo->Open( INFO_PATH, RageFile::WRITE|RageFile::STREAMED ) )
fprintf( stderr, "Couldn't open %s: %s\n", INFO_PATH, g_fileInfo->GetError().c_str() );
}
void RageLog::SetFlushing( bool b )
+2
View File
@@ -33,11 +33,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 SetFlushing( bool b ); // enable or disable flushing
void SetTimestamping( bool b ); // enable or disable timestamping
private:
bool m_bLogToDisk;
bool m_bInfoToDisk;
bool m_bFlush;
bool m_bTimestamping;
bool m_bShowLogOutput;
+29
View File
@@ -29,6 +29,8 @@
#include "arch/LoadingWindow/LoadingWindow.h"
#include "time.h"
#include "ProductInfo.h"
#include "SDL_utils.h"
#include "Screen.h"
@@ -805,6 +807,31 @@ void __cdecl main()
*/
#endif
#if defined(HAVE_VERSION_INFO)
extern unsigned long version_num;
extern const char *version_time;
#endif
static void WriteLogHeader()
{
LOG->Info( PRODUCT_NAME_VER );
#if defined(HAVE_VERSION_INFO)
LOG->Info( "Compiled %s (build %lu)", version_time, version_num );
#endif
time_t cur_time;
time(&cur_time);
struct tm now;
localtime_r( &cur_time, &now );
LOG->Info( "Log starting %.4d-%.2d-%.2d %.2d:%.2d:%.2d",
1900+now.tm_year, now.tm_mon+1, now.tm_mday, now.tm_hour+1, now.tm_min, now.tm_sec );
LOG->Trace( " " );
}
int main(int argc, char* argv[])
{
#ifdef _XBOX
@@ -881,10 +908,12 @@ int main(int argc, char* argv[])
LOG->SetShowLogOutput( PREFSMAN->m_bShowLogOutput );
LOG->SetLogToDisk( PREFSMAN->m_bLogToDisk );
LOG->SetInfoToDisk( true );
LOG->SetFlushing( PREFSMAN->m_bForceLogFlush );
LOG->SetTimestamping( PREFSMAN->m_bTimestamping );
Checkpoints::LogCheckpoints( PREFSMAN->m_bLogCheckpoints );
WriteLogHeader();
/* This requires PREFSMAN, for PREFSMAN->m_bShowLoadingWindow. */
LoadingWindow *loading_window = MakeLoadingWindow();