Log.cpp
上传用户:pumpssky
上传日期:2007-12-07
资源大小:110k
文件大小:1k
- // Log.cpp: implementation of the CLog class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "gmark.h"
- #include "Log.h"
- #include "stdio.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CLog::CLog()
- {
- fp = NULL;
- }
- CLog::~CLog()
- {
- }
- void CLog::Open(LPCSTR filename)
- {
- fp = fopen( filename, "wtc");
- InitializeCriticalSection( &m_CriticalSection );
- }
- void CLog::Write(LPCSTR message)
- {
- EnterCriticalSection(&m_CriticalSection);
- SYSTEMTIME systime;
- GetLocalTime(&systime);
- DWORD dwTickCount = GetTickCount();
-
- if( fp && message )
- {
- fprintf( fp, "%d-%d-%d %d-%d-%d-%d ",
- systime.wYear, systime.wMonth, systime.wDay,
- systime.wHour, systime.wMinute, systime.wSecond, dwTickCount/*systime.wMilliseconds*/ );
- fwrite( message, sizeof(char), strlen(message), fp );
- fputs("n", fp);
-
- fflush(fp);
- }
- LeaveCriticalSection(&m_CriticalSection);
- }
- void CLog::Close()
- {
- if(fp)
- {
- fclose(fp);
- fp = NULL;
- }
- DeleteCriticalSection( &m_CriticalSection );
- }