123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*************************************************************
- /* Copyright (C), 2008-2010, StoneU Tech. Co., Ltd.
- /* 文件名: Log.h
- /* 作者: Jesse
- /* 创建日期: 2010-07-16
- /* 版本号: V1.0
- /* 描述: 对Log4cpp日志进行封装
- /* 其它:
- /* 主要类模块: CLog类,维护一个m_pLog静态指针,所有日志操作都必须通过该指针
- /* 历史修改记录:
- /* 作者 时间 版本 描述
- /* Jesse 10/07/16 1.0 创建这个模块
- ***************************************************************/
- #ifndef _LOG_H
- #define _LOG_H
- #if _MSC_VER >= 1000
- #pragma once
- #endif // _MSC_VER >= 1000
- extern "C"
- {
- #include "log4c.h"
- }
- namespace SToneULog
- {
- #define LOG4C_BUFFER_SIZE_MAX 1024*10
- static int g_nLogNum = 0;
- static log4c_category_t* g_pRoot = NULL;
- class CLog
- {
- private:
- //static CLog* m_pLog;
- const char *m_pFileName;
- const char *m_pFuncName;
- int m_nLinNo;
- public:
- CLog(const char *pFileName, const char *pFuncName, int nLineNo):
- m_pFileName(pFileName),
- m_pFuncName(pFuncName),
- m_nLinNo(nLineNo)
- {
- }
- ~CLog()
- {
- };
- //static CLog* GetInstancePtr();
- //static CLog GetInstance(const char *pFileName, const char *pFuncName, int nLineNo);
- //int CreateLog(char chLogPath[MAX_PATH]="");
- //void DestroyLog();
- //void Output(const char *pFormat, ...);
- void operator()(const char *pszFmt, ...) const
- {
- char strMsgBuffer[LOG4C_BUFFER_SIZE_MAX] = {0};
- va_list va;
- sprintf( strMsgBuffer, "%d Function %s at line %d in file %s;",
- ++g_nLogNum, m_pFuncName, m_nLinNo, m_pFileName );
- strncat( strMsgBuffer, pszFmt, strlen(pszFmt) + 2 );
- va_start(va, pszFmt);
- log4c_category_vlog(g_pRoot, LOG4C_PRIORITY_ERROR, strMsgBuffer, va);
- va_end(va);
- }
- void operator()(const wchar_t *pszFmt, ...) const
- {
- va_list ptr;
- va_start(ptr, pszFmt);
- va_end(ptr);
- }
- };
- };
- #define LOG4C SToneULog::CLog(__FILE__, __FUNCTION__, __LINE__)
- #endif
|