89 lines
2.0 KiB
C++
89 lines
2.0 KiB
C++
#if !defined(LOGGER_H__5142BB38_5565_4124_88A4_56EA08298154__INCLUDED_)
|
|
#define LOGGER_H__5142BB38_5565_4124_88A4_56EA08298154__INCLUDED_
|
|
|
|
#include <afxwin.h>
|
|
#include <afxext.h>
|
|
#include <string>
|
|
#include <wincon.h>
|
|
#include <string.h>
|
|
#include <share.h>
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include "stdafx.h"
|
|
#include <locale.h>
|
|
#include <string>
|
|
using namespace std;
|
|
const long LOGINIT = 0x0001;
|
|
const long LOGACTIONS = 0x0002;
|
|
const long LOGCOMM = 0x0004;
|
|
const long LOGFLUSH = 0x0008;
|
|
|
|
extern string ConvertCharToString(char* a, int size);
|
|
extern void DelFiles(string path);
|
|
extern string ByteArrayToString(byte byteArray[]);
|
|
|
|
|
|
|
|
class CLogger
|
|
{
|
|
public:
|
|
CLogger(CString m_Name)
|
|
{
|
|
//设置中文环境
|
|
//setlocale(LC_ALL, "Chinese-simplified");
|
|
setlocale(LC_ALL, "en_US.UTF-8");
|
|
|
|
IsEnabledLog = false;
|
|
m_File = nullptr;
|
|
CString Path = _T(""); // Speed optimization - noticed slow in GlowCode
|
|
if (Path.IsEmpty())
|
|
{
|
|
CString tmpPath;
|
|
GetModuleFileName(nullptr, tmpPath.GetBuffer(255), 255);
|
|
tmpPath.ReleaseBuffer();
|
|
tmpPath.TrimRight();
|
|
int nLastSlash = tmpPath.ReverseFind('\\');
|
|
if (nLastSlash >= 0)
|
|
tmpPath = tmpPath.Left(nLastSlash);
|
|
else
|
|
tmpPath.Empty();
|
|
Path = tmpPath;
|
|
}
|
|
else //文件夹不为空
|
|
{
|
|
TRACE0("Log File Path: \n", CStringA());
|
|
//DelFiles(CT2A(m_Name.GetString()));
|
|
}
|
|
|
|
|
|
m_FileName = Path + m_Name; //_T("\\SO7_SSILog.txt");
|
|
m_lLogMask = 0;
|
|
InitializeCriticalSection(&m_lockLogger);
|
|
};
|
|
|
|
~CLogger()
|
|
{
|
|
if (m_File)
|
|
fclose(m_File);
|
|
DeleteCriticalSection(&m_lockLogger);
|
|
};
|
|
void SendAtTime(const TCHAR* buffer);
|
|
void Send(LPCTSTR, ...);
|
|
void SendAndFlush(LPCTSTR, ...);
|
|
void SendAndFlushPerMode(LPCTSTR, ...);
|
|
void SendAndFlushWithTime(LPCTSTR, ...);
|
|
|
|
|
|
|
|
bool IsEnabledLog/* = false*/; //是否启用日志
|
|
CString m_FileName;
|
|
long m_lLogMask;
|
|
FILE* m_File;
|
|
_TCHAR m_Str[20000];
|
|
_TCHAR m_Str2[20000];
|
|
CRITICAL_SECTION m_lockLogger;//临界区
|
|
};
|
|
|
|
|
|
#endif // !defined(LOGGER_H__5142BB38_5565_4124_88A4_56EA08298154__INCLUDED_)
|