//打印日志记录 root.emerg("this is an emrge"); root.alert("this is an alert"); root.crit("this is a critical"); root.error("this is an error"); root.warn("this is a warn"); root.notice("this is a notice"); root.info("this is an info"); root.debug("this is a debug");
model1.debug("123456"); } intmain() { test0();
return0; }
输出结果
1684758947 FATAL : this is an emrge 1684758947 ALERT : this is an alert 1684758947 CRIT : this is a critical 1684758947 ERROR : this is an error 1684758947 WARN : this is a warn 1684758947 NOTICE : this is a notice 1684758947 INFO : this is an info 1684758947 DEBUG : this is a debug 1684758947 DEBUG register : 123456
voidtest0() { //设置三个对象,分别对应控制台,文件,回卷文件 OstreamAppender* posAp = newOstreamAppender("console",&cout); FileAppender* FileAp = newFileAppender("FileAp","test.log"); RollingFileAppender* RollingFileAp = newRollingFileAppender("RollingFileAp","a.log",5000,10); PatternLayout* ptnLayout1 = newPatternLayout(); PatternLayout* ptnLayout2 = newPatternLayout(); ptnLayout2->setConversionPattern("%d [%c] [%p] %m %n"); ptnLayout2->setConversionPattern("%d [%c] [%p] %m %n"); //一个目的地只能对应一个布局,一个布局只能对应一个目的地 posAp->setLayout(newBasicLayout()); FileAp->setLayout(ptnLayout1); RollingFileAp->setLayout(ptnLayout2); Category& root = Category::getRoot(); root.setAppender(posAp); root.addAppender(FileAp); root.addAppender(RollingFileAp); root.setPriority(Priority::DEBUG); Category& model = root.getInstance("register"); for(int i = 0;i < 100;++i) { root.emerg("this is an emrge"); root.alert("this is an alert"); root.crit("this is a critical"); root.error("this is an error"); root.warn("this is a warn"); root.notice("this is a notice"); root.info("this is an info"); root.debug("this is a debug"); model.emerg("this is an emrge"); model.alert("this is an alert"); model.crit("this is a critical"); model.error("this is an error"); model.warn("this is a warn"); model.notice("this is a notice"); model.info("this is an info"); model.debug("this is a debug"); } Category::shutdown; } intmain() { test0(); return0; }
输出结果
1684842384 FATAL : thisis an emrge 1684842384 ALERT : thisis an alert 1684842384 CRIT : thisis a critical 1684842384 ERROR : thisis an error 1684842384 WARN : thisis a warn 1684842384 NOTICE : thisis a notice 1684842384 INFO : thisis an info 1684842384 DEBUG : thisis a debug 1684842384 FATAL register : thisis an emrge 1684842384 ALERT register : thisis an alert 1684842384 CRIT register : thisis a critical 1684842384 ERROR register : thisis an error 1684842384 WARN register : thisis a warn 1684842384 NOTICE register : thisis a notice 1684842384 INFO register : thisis an info 1684842384 DEBUG register : thisis a debug ... ... 1684842384 FATAL : thisis an emrge 1684842384 ALERT : thisis an alert 1684842384 CRIT : thisis a critical 1684842384 ERROR : thisis an error 1684842384 WARN : thisis a warn 1684842384 NOTICE : thisis a notice 1684842384 INFO : thisis an info 1684842384 DEBUG : thisis a debug 1684842384 FATAL register : thisis an emrge 1684842384 ALERT register : thisis an alert 1684842384 CRIT register : thisis a critical 1684842384 ERROR register : thisis an error 1684842384 WARN register : thisis a warn 1684842384 NOTICE register : thisis a notice 1684842384 INFO register : thisis an info 1684842384 DEBUG register : thisis a debug 1684842384 FATAL : thisis an emrge 1684842384 ALERT : thisis an alert 1684842384 CRIT : thisis a critical 1684842384 ERROR : thisis an error 1684842384 WARN : thisis a warn 1684842384 NOTICE : thisis a notice 1684842384 INFO : thisis an info 1684842384 DEBUG : thisis a debug 1684842384 FATAL register : thisis an emrge 1684842384 ALERT register : thisis an alert 1684842384 CRIT register : thisis a critical 1684842384 ERROR register : thisis an error 1684842384 WARN register : thisis a warn 1684842384 NOTICE register : thisis a notice 1684842384 INFO register : thisis an info 1684842384 DEBUG register : thisis a debug