log4qt使用示例

来源:互联网 发布:三维人像综合数据门 编辑:程序博客网 时间:2024/05/17 22:07

1.pro 包含log4qt.pri




2.设置日志属性

# Libfetion-gui project# define the root logger with two appenders writing to console and file log4j.rootLogger =DEBUG,Console####outputlog to console##########define the appender named CONSOLElog4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p %x %m%n log4j.logger.A1=DEBUG,CONSOLE,A1log4j.appender.A1=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.A1.File=logs/a1.txtlog4j.appender.A1.layout=org.apache.log4j.PatternLayoutlog4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] - %m%nlog4j.logger.A2=DEBUG,CONSOLE,A2 log4j.appender.A2=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.A2.File=logs/a2.txtlog4j.appender.A2.layout=org.apache.log4j.PatternLayoutlog4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] - %m%nlog4j.logger.A3=DEBUG,CONSOLE,A3 log4j.appender.A3=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.A3.File=logs/a3.txtlog4j.appender.A3.layout=org.apache.log4j.PatternLayoutlog4j.appender.A3.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] - %m%n


3.代码

#include "widget.h"#include <QApplication>#include "log4qt/logger.h"#include "log4qt/basicconfigurator.h"#include "log4qt/propertyconfigurator.h"#include <qmessagebox.h>#include <QDebug>int main(int argc, char *argv[]){    QApplication a(argc, argv);    Log4Qt::BasicConfigurator::configure();    Log4Qt::PropertyConfigurator::configure(QCoreApplication::applicationDirPath() + "/log4qt.properties");    Log4Qt::Logger *qqqq = Log4Qt::Logger::logger("A1");    qqqq->info("the message of log");//the log save at logs/a1.log    Log4Qt::Logger *a2 = Log4Qt::Logger::logger("A2");    a2->info("the message of log");//the log save at logs/a2.log    Log4Qt::Logger *a3 = Log4Qt::Logger::logger("A3");    a3->info("the message of log");//the log save at logs/a3.log    Widget w;    w.show();    return a.exec();}


4.log4qt 下载地址

http://download.csdn.net/download/sunxiaopengsun/10123302

原创粉丝点击