Log4j 配置打印到控制台和文件
我的 log4jproperties:
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=checkLog.log
log4j.appender.file.threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
我想将 log4j 打印到控制台和文件,但是 当我导入 slf4j-log12-1.6.4.jar 时,它仅在文件中打印并引发此异常:
Could not instantiate class [org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout].
当我导入 slf4jsimple-1.6.4.jar 时,它仅打印到控制台,没有异常,
那么我应该导入什么?
以及我应该更改属性以打印堆栈跟踪。我正在使用这个:
logger.error("ERROR!: " + e);
但我只看到:
16:59:28,703 ERROR PlayOffPanel:275 - ERROR!: java.lang.IndexOutOfBoundsException:
Index: 15, Size: 15
My log4jproperties:
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=checkLog.log
log4j.appender.file.threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
I wanna to print log4j to console and to file but
when I import slf4j-log12-1.6.4.jar it prints just in file and it throws this exception:
Could not instantiate class [org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout].
when I import slf4jsimple-1.6.4.jar it print just to console with no exception
so what I should import ?
And what I should change in properties to print stacktrace. I am using this:
logger.error("ERROR!: " + e);
but I only see:
16:59:28,703 ERROR PlayOffPanel:275 - ERROR!: java.lang.IndexOutOfBoundsException:
Index: 15, Size: 15
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该在开头有这一行:
You should have this line at the beginning: