Files
itgmania212121/stepmania/src/RageLog.cpp
T

109 lines
2.0 KiB
C++
Raw Normal View History

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:19:49 +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-05-01 19:14:55 +00:00
#include "dxerr8.h"
2002-08-22 19:33:28 +00:00
#pragma comment(lib, "DxErr8.lib")
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 );
// Open log file and leave it open. Let the OS close it when the app exits
m_fileLog = fopen( LOG_FILE_NAME, "w" );
SYSTEMTIME st;
GetLocalTime( &st );
this->Trace( "Last compiled on %s.", __TIMESTAMP__ );
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 );
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();
}
void RageLog::Trace( LPCTSTR fmt, ...)
2002-05-01 19:14:55 +00:00
{
va_list va;
va_start(va, fmt);
CString sBuff = vssprintf( fmt, va );
sBuff += "\n";
fprintf( m_fileLog, sBuff );
printf( sBuff );
#ifdef DEBUG
this->Flush(); // implicit flush
#endif
}
void RageLog::Trace( HRESULT hr, LPCTSTR fmt, ...)
2002-05-01 19:14:55 +00:00
{
va_list va;
va_start(va, fmt);
CString s = vssprintf( fmt, va );
s += ssprintf( "(%s)", DXGetErrorString8(hr) );
this->Trace( s );
}
void RageLog::Warn( LPCTSTR fmt, ...)
{
va_list va;
va_start(va, fmt);
CString sBuff = vssprintf( fmt, va );
Trace( "/////////////////////////////////////////\n"
"WARNING: %s\n"
"/////////////////////////////////////////",
sBuff );
2002-05-01 19:14:55 +00:00
}
void RageLog::Flush()
{
fflush( m_fileLog );
}