在程序中一般需要添加日志管理的记录,在学习Httpserver的过程中,学习到了日志管理模块,将QtwebApp的日志模块提取出来可作为一般性程序的日志管理,记录实验的过程,项目源代码也附在后面。
项目运行结果

项目代码结构

参考教程
QtWebApp官方说明http://stefanfrings.de/qtwebapp/tutorial/index.html#logging2
官方代码示例:http://stefanfrings.de/qtwebapp/QtWebApp.zip
使用步骤:
1、引用日志管理模块
在工程pro文件中引用官方的logging模块

2、创建并配置文件ini信息
ini文件,我通过新建文本文件再修改后缀名为ini,Qt中不能直接添加ini文本文件,并添加一些日志的配置信息,确保fileName中的路径文件夹是存在。

更多解释见官方的说明:Writing web server applications with QtWebApp

3、实例日志的全局指针, 访问整个程序
在global.h文件中添加:

glabal.h代码:
#ifndef GLOBAL_H
#define GLOBAL_H
#include "filelogger.h"
using namespace stefanfrings;
extern FileLogger* logger;
#endif // GLOBAL_H
glabal.cpp代码:
#include "global.h"
FileLogger* logger;
4、全局使用日志实例
