log4j输出文件的格式问题
我想要输出日志的格式为TXT格式
log4j.appender.R.File=C:/log.txt
log4j.appender.R.layout=org.apache.log4j.TXTLayout
这么设置好像不行,并没有生成文件
请指教,谢谢~~
------解决方案--------------------建议你看看log4j的用法吧,网上很多的
------解决方案--------------------log4j.appender.HEJIAMAIN = org.apache.log4j.DailyRollingFileAppender
log4j.appender.HEJIAMAIN.File = /home/htdocs/webapp/logs/main.log
------解决方案--------------------Appender 为日志输出目的地,Log4j提供的appender有以下几种:
org.apache.log4j.ConsoleAppender(控制台),
org.apache.log4j.FileAppender(文件),
org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件),
org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生一个新的文件),
org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
Layout:日志输出格式,Log4j提供的layout有以下几种:
org.apache.log4j.HTMLLayout(以HTML表格形式布局),
org.apache.log4j.PatternLayout(可以灵活地指定布局模式),
org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),
org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)
有org.apache.log4j.TXTLayout?
------解决方案--------------------网上google 很多相关的
------解决方案--------------------log4j.rootLogger=, A1, A2
# A1 is set to be ConsoleAppender sending its output to System.out
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# The conversion pattern consists of date in ISO8601 format, level,
# thread name, logger name truncated to its rightmost two components
# and left justified to 17 characters, location information consisting
# of file name (padded to 13 characters) and line number, nested
# diagnostic context, the and the application supplied message
# log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-10c{10} (%10F:%L) %2x - %m%n
# Appender A2 writes to the file "test ".
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=test.txt
# Truncate 'test ' if it aleady exists.
log4j.appender.A2.Append=true
# Appender A2 uses the PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n
------解决方案--------------------# 设定日志文件的输出模式
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern=yyyyMMdd
# ${log.home}通过参数-D指定,比如启动WebLogic时加入参数-Dpafa.log.home=c:/
log4j.appender.logfile.File=${log.home}/tutorial/DATE.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{MM/dd HH:mm:ss} [%-3p] %c{1}: %m%n