⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logthread.h

📁 日志模块代码
💻 H
字号:
/*********************************************************************
* 版权所有 (C)2007, 深圳市中兴通讯股份有限公司。
* 
* 文件名称: LogThread.h
* 文件标识: 
* 内容摘要: 日志线程类定义
* 其它说明: 
* 当前版本: V1.00
* 作    者: 
* 完成日期: 2007/03/15
* 
* 修改记录1:
*    修改日期:2005
*    版 本 号:V1.00
*    修 改 人:陈建友
*    修改内容:原始版本
* 修改记录2:
*    修改日期:2007/02/26
*    版 本 号:V1.00
*    修 改 人:王耀峰
*    修改内容:将ICE库替换为Boost库
* 修改记录3:
*    修改日期:2007/03/15
*    版 本 号:V1.00
*    修 改 人:张 帆
*    修改内容:优化代码,如下所述:
*              (1)采用Boost.Threads库,“日志线程”创建即初始化,然后执行 operator ()
*              (2)移除原来的Initialize()函数,相应的初始化工作全部移至构造函数
*              (3)重载 operator () ,这是“日志线程”的执行逻辑
**********************************************************************/
#ifndef LOGTHREAD_H
#define LOGTHREAD_H

#include <string>
#include <vector>
#include <fstream>

#ifndef LMSSERVER
    #include "ILogger.h"
#else
    #include "LSComm.h"
#endif

#include "SynQueue.h"

class CLogThread
{
public:
    CLogThread(const NOP::RemarkItem& Item,
               const std::string& strLogPath,
               int iMaxLine,
               int iHistoryAmnt);
    virtual ~CLogThread(void);

    void operator()();

    void AddItem(const NOP::LogItem& Item);
    const int GetThreadID(void);

private:
    bool IsStopItem(const NOP::LogItem& Item);
    bool IsMatchedLevelItem(const NOP::LogItem& Item);
    bool IsMatchedRemarkItem(const NOP::LogItem& Item);
    bool IsFileFull(void);
    bool ReArrangeLogFiles(void);

    std::string FormatItem(const NOP::LogItem& Item);
    const std::string FormatTime(const SYSTEMTIME &ltime);
    void itoaWithSpecifiedWidth(int iNum, std::string& strNum, int iWidth);
    void CreateLogFileName(int iLogFileNo, std::string& strLogFileName);

private:
    std::string m_sstrLogPath;   // 日志文件的保存路径
    int m_siMaxLineNum;          // 日志文件的最大行数
    int m_siHistoryAmnt;         // 历史日志文件的最大数目
    NOP::RemarkItem m_RemarkItem;       // 日志文件的备注项

    static const std::string m_sstrLogFileNamePre;  // 日志文件名的前缀
    static const std::string m_sstrLogFileNameSuf;  // 日志文件名的后缀

    const std::string m_strLogFile;	                // 用于日常记录的日志文件名称
    std::vector<std::string> m_vstrHistoryLogFiles;	// 定义字符串向量数组用来存放历史日志记录的文件名
                                                    // 注意,该数组的元素会动态增加
	int m_iCurHistoryLogFile;	                    // 用来指示当前已经使用的历史日志				

    std::fstream m_LogFile;             // 用来记录的日志文件
    int m_iTotalLines;                  // 总行数

    int m_tid;                          // 线程ID  

    CSynQueue<NOP::LogItem> m_synQueue; // 日志队列(带有同步功能)  
};

#endif  // LOGTHREAD_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -