首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

log4j 写不出文本日志,该如何解决

2012-04-12 
log4j 写不出文本日志log4j:ERROR Category option 1 not a decimal integer.java.lang.NumberFormatE

log4j 写不出文本日志
log4j:ERROR Category option " 1 " not a decimal integer.
java.lang.NumberFormatException: For input string: " 1 "
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.apache.log4j.helpers.PatternParser.extractPrecisionOption(PatternParser.java:117)
at org.apache.log4j.helpers.PatternParser.finalizeConverter(PatternParser.java:235)
at org.apache.log4j.helpers.PatternParser.parse(PatternParser.java:187)
at org.apache.log4j.PatternLayout.setConversionPattern(PatternLayout.java:446)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:206)
at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:165)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:130)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:684)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
at org.apache.log4j.Logger.getLogger(Logger.java:105)
at Main.<clinit>(Main.java:17)
log4j:ERROR Could not find value for key log4j.appender.E
log4j:ERROR Could not instantiate appender named "E".

以上是报错。
程序照常运行,控制台照常再打日志。问题是文本文件没记录。

我的调用代码
static Logger logger = Logger.getLogger("");
logger.info("测试");

我的配置(另外附带问一下我需要1天1个日期文件夹,1小时1个.log文件的话该怎么改配置呢?):
 ### set log levels ###  
log4j.rootLogger = debug , stdout , D , E 
   
log4j.appender.stdout = org.apache.log4j.ConsoleAppender  
log4j.appender.stdout.Target = System.out  
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout  
log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{ 1 }:%L - %m%n  

log4j.appender.D = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.D.File = log/log.log  
log4j.appender.D.Append = true  
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout  
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n  


log4j.appender.D = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.D.File = log/error.log
log4j.appender.D.Append = true  
log4j.appender.D.Threshold = ERROR
log4j.appender.D.layout = org.apache.log4j.PatternLayout  
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

[解决办法]
很明显你的log配置文件有问题
DailyRollingFileAppender这个用的多
生成文件夹还有每小时生成一个.log文件的还真没用过
[解决办法]
log4j.appender.stdout =org.apache.log4j.DailyRollingFileAppender//每天分割文件
log4j.appender.stdout .File=D:\project.log//文件存储地址
log4j.appender.stdout .DatePattern='.'yyyy-MM-dd//以日期作为文件名

log4j.appender.stdout = org.apache.log4j.ConsoleAppender //是打印到控制台不是文件




[解决办法]
不懂 关注  帮顶 学习
[解决办法]
学习 回复内容太短了!
[解决办法]
log4j.rootLogger = ERROR, stdout, common

log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t] - [%p] %m%n

log4j.appender.common = org.apache.log4j.DailyRollingFileAppender
log4j.appender.common.Append = true
log4j.appender.common.File = ${webapp.root}/logs/log.log
log4j.appender.common.DatePattern = '.'yyyy-MM-dd
#log4j.appender.common.Threshold = DEBUG
log4j.appender.common.layout = org.apache.log4j.PatternLayout
log4j.appender.common.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] - [%p] %m%n

log4j.logger.org.hibernate=ERROR
log4j.logger.org.hibernate.SQL=ERROR

热点排行