打酱油的萧萧

一个打酱油的程序员
[转]log4cxx以时间,大小的备份

[转]Log4cxx配置文件介绍

萧萧 posted @ 2010年8月04日 17:24 in C/C++ with tags log4cxx c++ , 4269 阅读

Log4cxx配置由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式。

1.日志信息的优先级

Logger的语法:

log4j.rootLogger = [ level ] , appenderName, appenderName, …

 

其中,level 是日志记录的优先级,分为OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者自定义的级别。

Log4j建议只使用四个级别,优先级从高到低分别是ERROR、WARN、INFO、DEBUG。

通过在这里定义的级别,可以控制到应用程序中相应级别的日志信息的开关。

比如这里定义了INFO级别,则应用程序中所有DEBUG级别的日志信息将不被打印出来。 

appenderName名字任意,用来标示日志信息输出到哪里,可以同时指定多个日志信息的输出目的地 。

 

Appender的语法:

log4j.appender.appenderName = fully.qualified.name.of.appender.class

log4j.appender.appenderName.option1 = value1

log4j.appender.appenderName.option = valueN

 

其中,Log4j提供的appender有以下几种:

org.apache.log4j.ConsoleAppender 控制台

org.apache.log4j.FileAppender 文件

org.apache.log4j.DailyRollingFileAppender 每天产生一个日志文件

org.apache.log4j.RollingFileAppender 文件大小到达指定尺寸的时候产生一个新的文件

org.apache.log4j.WriterAppender 将日志信息以流格式发送到任意指定的地方

 

2.日志信息的输出格式

Layout的语法:

log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class

log4j.appender.appenderName.layout.option1 = value1

log4j.appender.appenderName.layout.option = valueN

 

3.Log4j提供的Layout有以下几种:

org.apache.log4j.HTMLLayout 以HTML表格形式布局

org.apache.log4j.PatternLayout 可以灵活地指定布局模式

org.apache.log4j.SimpleLayout 包含日志信息的级别和信息字符串

org.apache.log4j.TTCCLayout 包含日志产生的时间、线程、类别等等信息

 

Log4j采用类似C语言中的printf函数的打印格式格式化日志信息,打印参数如下:

%m 输出代码中指定的消息

%p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL

%r 输出自应用启动到输出该log信息耗费的毫秒数

%c 输出所属的类目,通常就是所在类的全名

%t 输出产生该日志事件的线程名

%n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n” 

 

4. 例子:

# 设置root logger为DEBUG级别,使用了ca和fa两个Appender

log4j.rootLogger=DEBUG, ca, fa

 

#对Appender fa进行设置:

# 这是一个文件类型的Appender,

# 其输出文件(File)为./output.log,

# 输出方式(Append)为覆盖方式,

# 输出格式(layout)为PatternLayout

log4j.appender.fa=org.apache.log4j.FileAppender 

log4j.appender.fa.File=./output.log

log4j.appender.fa.Append=false

log4j.appender.fa.layout=org.apache.log4j.PatternLayout 

log4j.appender.fa.layout.ConversionPattern=%d [%t] %-5p %.16c - %m%n

 

#对Appender ca进行设置:

# 这是一个控制台类型的Appender

#  输出格式(layout)为PatternLayout

log4j.appender.ca=org.apache.log4j.ConsoleAppender 

log4j.appender.ca.layout=org.apache.log4j.PatternLayout 

log4j.appender.ca.layout.ConversionPattern=%d [%t] %-5p %.16c - %m%n

slope game 说:
2018年3月29日 17:42

%m 输出代码中指定的消息!!

the impossible quiz 说:
2018年10月15日 15:45

Your post is great and meaningful. Thank you for sharing this article. I would like to receive better and better articles.

hotmail entrar 说:
2018年11月28日 18:51

I was a girl, but clumsy things. I do not know how to cook, sew, above, ca. I have too insipid and tedious, but that's my personality. It's hard to change

Douchebag Workout 说:
2018年11月29日 16:37

Thank you for sharing this exciting resource with me and the world. Wish you always luck.

uphill rush 6 说:
2018年12月01日 12:20

则应用程序中所有DEBUG级别的日志信息将不被打印出来。

appenderName名字任意,用来标示日志信息输出到哪里,可以同时指定多个日志信息的输出目的地 。

www.hotmail.com 说:
2019年1月22日 16:06

The article you have shared here very good.

halo pc 说:
2019年2月04日 18:57

I missed to read like more post and blogs...

halo pc games 说:
2019年2月04日 19:00

Some time you wants to read something different for knowledge. But we rarer fount that.

Superfighters 说:
2019年3月06日 15:18

I Loved The Way You Discuss The Topic Great Work Thanks For The Share.

Best Parental Contr 说:
2019年5月29日 14:01

Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments

Effective Email Mar 说:
2019年5月29日 14:02

I'ts an amazing website, really enjoy your articles. Helpful and interesting too. Keep doing this in future.

LIC Merchant 说:
2019年6月01日 10:40

This is a very good post .Thanks for letting us know some good tips .
I like your many articles it will help not only me and also many

Is Ytmp3.cc Safe to 说:
2019年6月21日 21:27

Nice write-up. A good article always come up with new and exciting information. Keep up the amazing work.

Lucina J Lee 说:
2019年8月02日 15:56

Really very happy to say, your post is very interesting to read.I never stop myself to say something about it. You’re doing a great job. Keep it up, the above link will get you to the free gift card generator.

hole io 说:
2019年9月03日 15:11

This is a great little post with some valuable tips. I totally agree. The way you bring passion and engagement
into the things you do can really change your outlook on live.

192.168.l.l 说:
2019年9月04日 20:35

This code helps me a lot! Thank you so much!

192.168.l.l

email login 说:
2020年2月21日 15:04

Gmail is now the most used email service on the internet with more than 1 billions users, create your email today with the step by step tutorial on email login

9xFlix 2020 说:
2020年3月07日 14:10

eally very happy to say, your post is very interesting to read.

9xFlix 2020 说:
2020年3月07日 14:11

eally very happy to say, your post is very interesting to read.

Pdf Drive 说:
2020年3月07日 14:11

The way you bring passion and engagement
into the things you do can really change your outlook on live.

Movie4me 说:
2020年3月07日 14:12

Nice write-up. A good article always come up with new and exciting information.

Madras Rockers 说:
2020年3月07日 14:13

I was a girl, but clumsy things. I do not know how to cook, sew, above, ca. I have too insipid and tedious, but that's my personality. It's hard to change

tetris game 说:
2021年3月15日 12:29

感谢您与我们分享!

dino run 说:
2021年4月24日 15:39

Thanks for sharing this information. I just wanted to let you know that. I just viewed your website and I found it very interesting and informative

Things to do 说:
2021年8月09日 15:32

Staying at home is our new normal. Surfing social site, watching films, spending time with your family... are all thing we can do, but you also can plan for the next vacation with the suggestions from Things to do post

SENSINOVA 说:
2022年5月02日 13:18

Keep Blogging

Great share! Amazing write-up!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter