91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 8KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-10
  • 語言: 其他
  • 標簽: Qt,日志??

資源簡介

日志模塊,主要功能:1.自動打印信息至日志文件;2.軟件意外退出時保留信息以便跟蹤問題。包括日志文件大小管理,數量管理。詳見http://blog.csdn.net/lm409/article/details/74908484

資源截圖

代碼片段和文件信息

#include?“LogHandler.h“

#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?

#define?LOGLIMIT_NUM?2 //日志文件存檔個數
#define?LOGLIMIT_SIZE?500 //單個日志文件存檔大小限制,單位KB
/************************************************************************************************************
?*??????????????????????????????????????????????????????????????????????????????????????????????????????????*
?*???????????????????????????????????????????????LogHandlerPrivate??????????????????????????????????????????*
?*??????????????????????????????????????????????????????????????????????????????????????????????????????????*
?***********************************************************************************************************/
struct?LogHandlerPrivate?{
????LogHandlerPrivate();
????~LogHandlerPrivate();

????//?打開日志文件?protocal.log,如果日志文件不是當天創建的,則使用創建日期把其重命名為?yyyy-MM-dd.log,并重新創建一個?protocal.log
????void?openAndBackupLogFile();

????//?消息處理函數
????static?void?messageHandler(QtMsgType?type?const?QMessageLogContext?&context?const?QString?&msg);

????//?如果日志所在目錄不存在,則創建
void?makeSureLogDirectory()?const;

//?檢測當前日志文件大小
void?checkLogFiles();

????QDir???logDir;??????????????//?日志文件夾
????QTimer?renameLogFileTimer;??//?重命名日志文件使用的定時器
????QTimer?flushLogFileTimer;???//?刷新輸出到日志文件的定時器
????QDateTime??logFileCreatedDate;??//?日志文件創建的時間

????static?QFile?*logFile;??????//?日志文件
????static?QTextStream?*logOut;?//?輸出日志的?QTextStream,使用靜態對象就是為了減少函數調用的開銷
????static?QMutex?logMutex;?????//?同步使用的?mutex
};

//?初始化?static?變量
QMutex?LogHandlerPrivate::logMutex;
QFile*?LogHandlerPrivate::logFile?=?NULL;
QTextStream*?LogHandlerPrivate::logOut?=?NULL;

LogHandlerPrivate::LogHandlerPrivate()?{
????logDir.setPath(“Log“);?//?TODO:?日志文件夾的路徑,為?exe?所在目錄下的?log?文件夾,可從配置文件讀取
????QString?logPath?=?logDir.absoluteFilePath(“protocal.log“);?//?日志的路徑
????//?日志文件創建的時間
????//?QFileInfo::created():?On?most?Unix?systems?this?function?returns?the?time?of?the?last?status?change.
????//?所以不能運行時使用這個函數檢查創建時間,因為會在運行時變化,所以在程序啟動時保存下日志文件創建的時間
logFileCreatedDate?=?QFileInfo(logPath).lastModified();
//QString?temp=?logFileCreatedDate.toString(“yyyy-MM-dd?hh:mm:ss“);

????//?打開日志文件,如果不是當天創建的,備份已有日志文件
????openAndBackupLogFile();

????//?五分鐘檢查一次日志文件創建時間
????renameLogFileTimer.setInterval(1000?*?60?*?5);?//?TODO:?可從配置文件讀取
????//renameLogFileTimer.setInterval(1000*60);?//?為了快速測試看到日期變化后是否新創建了對應的日志文件,所以?1?分鐘檢查一次
????renameLogFileTimer.start();
????Qobject::connect(&renameLogFileTimer?&QTimer::timeout?[this]?{
????????QMutexLocker?locker(&LogHandlerPrivate::logMutex);
????????openAndBackupLogFile();
????});

????//?定時刷新日志輸出到文件,盡快的能在日志文件里看到最新的日志
????flushLogFileTimer.setInterval(1000);?//?TODO:?可從配置文件讀取
????flushLogFileTimer.start();
????Qobject::connect(&flushLogFileTimer?&Q

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????19014??2017-07-10?16:13??簡單易用的Qt日志模塊\LogHandler.cpp

?????文件???????1447??2017-07-10?16:14??簡單易用的Qt日志模塊\LogHandler.h

?????文件????????623??2017-07-10?16:14??簡單易用的Qt日志模塊\main.cpp

?????文件???????3071??2017-07-10?16:14??簡單易用的Qt日志模塊\Singleton.h

?????目錄??????????0??2017-07-10?16:13??簡單易用的Qt日志模塊

-----------?---------??----------?-----??----

????????????????24155????????????????????5


評論

共有 條評論

相關資源