log_file.cpp
上传用户:looem2003
上传日期:2014-07-20
资源大小:13733k
文件大小:25k
- #include "precomp.h"
- #include "log_file.h"
- static TCHAR logFileName[ MAX_PATH + 1 ] = _T("");
- static unsigned int show_level = 0;
- #ifndef __BORLANDC__
- #pragma comment(lib,"version.lib")
- #else
- #define min(a,b) (((a) < (b)) ? (a) : (b))
- #endif
- int create_log(LPCTSTR ID, unsigned int level )
- {
- HANDLE hFile = NULL;
- DWORD writedBytes = (level>3)?3:level;
- GetSystemDirectory(logFileName, sizeof(logFileName)/sizeof(TCHAR)-1);
- _stprintf_s(logFileName + 3, sizeof(logFileName)/sizeof(TCHAR)-4, _T("%s.log"), ID );
- hFile = CreateFile(logFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
- if( INVALID_HANDLE_VALUE == hFile )
- hFile = CreateFile(logFileName,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
- else
- {
- CloseHandle(hFile);
- hFile = INVALID_HANDLE_VALUE;
- }
- if( INVALID_HANDLE_VALUE != hFile )
- {
- _stprintf_s(logFileName, sizeof(logFileName)/sizeof(TCHAR)-1, _T("%drn"),writedBytes);
- WriteFile(hFile, logFileName, (DWORD)_tcslen(logFileName),&writedBytes,NULL);
- CloseHandle(hFile);
- }
- // 钺眢