?? simplelog.h
字號:
/***************************************************************
* Author: aron zhao
* Company: Intervision
* Last Update: 2005-01-17
* Copyright(c), Intervision Software Co., Ltd. Beijing.
* All Rights Reserved
*------------------------------------------------------------
* FileName: IVCLog.h
* Function Note: Sys Log implementation.
* Update note: Created at 2003-09-10
*****************************************************************/
//Level 1:正常流程不應該發生的故障:如new操作失敗,文件IO操作失敗,異常退出等等;
//Level 2:參數有效性判斷,以及指針NULL判斷為不符和規則;
//Level 3: 函數中途異常返回;
//Level 4: 命令消息的打印輸出;
//Level 5: 程序流程中重要變量內容的調試輸出;
//默認日志級別是3,按天產生日志,日志記錄加時間戳;如果沒有設置FileByDay|FileByName選項,默認為DisplayScreen即輸出到屏幕
#ifndef _IV_CLOG_H_
#define _IV_CLOG_H_
#define MAX_LEVEL 256
#define TBUF_SIZE 102400
#define PATH_MAX_SIZE 256
#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>
#endif
#define ANSI
#ifndef HAVE_STD_IOSTREAM
#define HAVE_STD_IOSTREAM
#endif
#include <string>
#include <stdarg.h>
#ifdef HAVE_STD_IOSTREAM
using namespace std;
#endif
enum LOGLEVEL {
FATAL = 1,
ERROR = 2,
NORMAL = 3,
INFO = 4,
DEBUG = 5
};
namespace SIMPLELOG
{
class SimpleLog
{
#if defined(WIN32)
CRITICAL_SECTION _mutex;
#else
pthread_mutex_t _mutex;
#endif
protected:
FILE *m_pf;
string m_Suffix;
string m_Prefix;
unsigned m_LogOptions;
unsigned m_LogLevel;
string m_LogFileName;
char m_strBuf[TBUF_SIZE];
char m_LogPath[PATH_MAX_SIZE];
bool m_bEnable;
string m_DebugFileName;
int m_LineNum;
//把時間格式從20030910061630改為2003 09-10 10:30:30
string FormatTime(string systemTime);
void lock();
void unlock();
//寫日志記錄的頭
short BeginLog(unsigned level);
//不加時間戳,每天只寫一次
short BeginLogHead(unsigned level);
//在文件名前加上路徑
string AddPath(const char *fileName);
void SetFileAndLine(const char *fileName,int lineNum)
{
m_DebugFileName = fileName;
m_LineNum = lineNum;
}
public:
// 調試輸出選擇
enum Options {
FileByDay = 1, //按天記日志
DateAndTime = 2,//加上時間戳
TraceLevel = 4,//輸出當前的級別
FileAndLine = 16,//此選項暫時沒用是為調試準備的
DisplayScreen = 32,//在屏幕上顯示
FileByName = 64 //按指定文件名產生日志
};
SimpleLog();
~SimpleLog();
SimpleLog( unsigned level,unsigned options,const char *filename );
void ReturnFileName(char *filename);
// 設置選項
void SetOptions(unsigned options );
void ClearOptions(unsigned options );
unsigned GetOptions( );
void AddOptions(unsigned options);
// 設置等級
void SetLevel(unsigned level );
unsigned GetLevel();
//判斷調試等級是否達到
bool CanTrace(unsigned level );
//設置日志文件名,只有在設置成FileByName時才有效
short SetFile( const char *fileName );
void SetLogPath( const char *logPath );
//打開關閉日志輸出
void Enable(bool enable=true )
{
m_bEnable = enable;
}
//按天產生日志時設置文件名的前綴與后綴,例如prefix是ivsender, suffix是log,時間是2005-01-17則文件名為ivsender20050117.log
void SetPrefixSuffix(const char *prefix, const char *suffix)
{
m_Prefix = prefix;
m_Suffix = suffix;
}
//清空文件流
void Flush()
{
fflush(m_pf);
}
//獲取系統時間,屏蔽操作系統
static string GetSystemTime();
static string GetFileTime();
//寫日志的函數,書寫格式與printf類似僅僅多了一個日志級別參數
#ifdef ANSI
long Userlog(unsigned level,const char *fmt,...);
#else
long Userlog(unsigned level,const char *fmt,va_alist);
#endif
#ifdef ANSI
long UserlogHead(unsigned level,const char *fmt,...);
#endif
};
} // End of namespace INTERVISION
#endif // (_IV_CLOG_H_)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -