xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

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

資源簡(jiǎn)介

日志模塊,主要功能:1.自動(dòng)打印信息至日志文件;2.軟件意外退出時(shí)保留信息以便跟蹤問題。包括日志文件大小管理,數(shù)量管理。詳見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 //日志文件存檔個(gè)數(shù)
#define?LOGLIMIT_SIZE?500 //單個(gè)日志文件存檔大小限制,單位KB
/************************************************************************************************************
?*??????????????????????????????????????????????????????????????????????????????????????????????????????????*
?*???????????????????????????????????????????????LogHandlerPrivate??????????????????????????????????????????*
?*??????????????????????????????????????????????????????????????????????????????????????????????????????????*
?***********************************************************************************************************/
struct?LogHandlerPrivate?{
????LogHandlerPrivate();
????~LogHandlerPrivate();

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

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

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

//?檢測(cè)當(dāng)前日志文件大小
void?checkLogFiles();

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

????static?QFile?*logFile;??????//?日志文件
????static?QTextStream?*logOut;?//?輸出日志的?QTextStream,使用靜態(tài)對(duì)象就是為了減少函數(shù)調(diào)用的開銷
????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“);?//?日志的路徑
????//?日志文件創(chuàng)建的時(shí)間
????//?QFileInfo::created():?On?most?Unix?systems?this?function?returns?the?time?of?the?last?status?change.
????//?所以不能運(yùn)行時(shí)使用這個(gè)函數(shù)檢查創(chuàng)建時(shí)間,因?yàn)闀?huì)在運(yùn)行時(shí)變化,所以在程序啟動(dòng)時(shí)保存下日志文件創(chuàng)建的時(shí)間
logFileCreatedDate?=?QFileInfo(logPath).lastModified();
//QString?temp=?logFileCreatedDate.toString(“yyyy-MM-dd?hh:mm:ss“);

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

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

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

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

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

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

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

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

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

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

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


評(píng)論

共有 條評(píng)論

相關(guān)資源