2002-05-01 19:14:55 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: RageLog
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-05-01 19:14:55 +00:00
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2002-08-22 20:21:37 +00:00
|
|
|
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include <fstream>
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2002-12-09 22:25:57 +00:00
|
|
|
#include "crash.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
|
|
|
|
|
RageLog* LOG; // global and accessable from anywhere in the program
|
|
|
|
|
|
|
|
|
|
// constants
|
|
|
|
|
#define LOG_FILE_NAME "log.txt"
|
|
|
|
|
|
|
|
|
|
RageLog::RageLog()
|
|
|
|
|
{
|
|
|
|
|
// delete old log files
|
|
|
|
|
DeleteFile( LOG_FILE_NAME );
|
|
|
|
|
|
2002-12-09 22:25:57 +00:00
|
|
|
// Open log file and leave it open.
|
2002-05-01 19:14:55 +00:00
|
|
|
m_fileLog = fopen( LOG_FILE_NAME, "w" );
|
|
|
|
|
|
|
|
|
|
SYSTEMTIME st;
|
|
|
|
|
GetLocalTime( &st );
|
|
|
|
|
|
2002-11-16 09:12:55 +00:00
|
|
|
#if defined(_MSC_VER)
|
2002-07-31 19:40:40 +00:00
|
|
|
this->Trace( "Last compiled on %s.", __TIMESTAMP__ );
|
2002-11-16 09:12:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
this->Trace( "Log starting %.4d-%.2d-%.2d %.2d:%.2d:%.2d",
|
2002-05-01 19:14:55 +00:00
|
|
|
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond );
|
2002-07-31 19:40:40 +00:00
|
|
|
this->Trace( "\n" );
|
2002-05-01 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RageLog::~RageLog()
|
|
|
|
|
{
|
|
|
|
|
Flush();
|
2002-05-29 09:47:24 +00:00
|
|
|
FreeConsole();
|
2002-05-01 19:14:55 +00:00
|
|
|
fclose( m_fileLog );
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-29 09:47:24 +00:00
|
|
|
void RageLog::ShowConsole()
|
|
|
|
|
{
|
|
|
|
|
// create a new console window and attach standard handles
|
|
|
|
|
AllocConsole();
|
|
|
|
|
freopen("CONOUT$","wb",stdout);
|
|
|
|
|
freopen("CONOUT$","wb",stderr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RageLog::HideConsole()
|
|
|
|
|
{
|
|
|
|
|
FreeConsole();
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-26 06:40:49 +00:00
|
|
|
void RageLog::Trace( const char *fmt, ...)
|
2002-05-01 19:14:55 +00:00
|
|
|
{
|
|
|
|
|
va_list va;
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
|
CString sBuff = vssprintf( fmt, va );
|
2002-08-26 06:40:49 +00:00
|
|
|
va_end(va);
|
2002-05-01 19:14:55 +00:00
|
|
|
|
2002-10-29 07:58:44 +00:00
|
|
|
fprintf( m_fileLog, "%s\n", sBuff.GetString() );
|
|
|
|
|
printf( "%s\n", sBuff.GetString() );
|
2002-12-09 22:25:57 +00:00
|
|
|
CrashLog(sBuff);
|
2002-05-01 19:14:55 +00:00
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
this->Flush(); // implicit flush
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-26 06:40:49 +00:00
|
|
|
void RageLog::Warn( const char *fmt, ...)
|
2002-07-31 19:40:40 +00:00
|
|
|
{
|
|
|
|
|
va_list va;
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
|
CString sBuff = vssprintf( fmt, va );
|
2002-08-26 06:40:49 +00:00
|
|
|
va_end(va);
|
2002-07-31 19:40:40 +00:00
|
|
|
|
|
|
|
|
Trace( "/////////////////////////////////////////\n"
|
|
|
|
|
"WARNING: %s\n"
|
|
|
|
|
"/////////////////////////////////////////",
|
2002-10-29 07:58:44 +00:00
|
|
|
sBuff.GetString() );
|
2002-05-01 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RageLog::Flush()
|
|
|
|
|
{
|
|
|
|
|
fflush( m_fileLog );
|
|
|
|
|
}
|