我的日志记录存在问题,其中slf4j没有记录消息/ stacktrace的文件名和行号。
码:
private static Logger log = LoggerFactory.getLogger(SomeService.class); @Override public void aService(ServiceAdmin sa) throws Exception { log.debug(LoggerFactory.class.toString()); log.debug(log.getClass().getName()); log.debug("Setup Example"); SomeService.setDefault(Example.getInstance()); log.debug("Example finished"); }日志:
2015-04-20 14:47:26.573 DEBUG [main] null:-1 - class org.slf4j.LoggerFactory 2015-04-20 14:47:26.574 DEBUG [main] null:-1 - ch.qos.logback.classic.Logger 2015-04-20 14:47:26.574 DEBUG [main] null:-1 - Setup Example 2015-04-20 14:47:26.575 DEBUG [main] null:-1 - SomeService finished这是我的logback.xml与该类相关的部分
<logger name="com.bredband.nexusgw.services"> <level value="debug" /> <appender-ref ref="nexusservice" /> </logger> <appender name="nexusservice" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>/var/log/nexus/nexusjgw/jgw/Service.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <FileNamePattern>/var/log/nexus/nexusjgw/jgw/Service.log.%i </FileNamePattern> <MinIndex>1</MinIndex> <MaxIndex>5</MaxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>200MB</MaxFileSize> </triggeringPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>debug</level> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] %F:%L - %m%n</Pattern> </layout> </appender>有没有人见过这个,可以指出我正确的方向?
BR Stefan
- 更新 -
我将%F更改为%C,但这并没有改变日志中的任何内容。 然后我尝试在我的ant文件的javac头中设置debug =“on”,现在它记录了classname和行号。
2015-04-21 08:28:55.910 DEBUG [main] Service.java:20 - class org.slf4j.LoggerFactory 2015-04-21 08:28:55.911 DEBUG [main] Service.java:21 - ch.qos.logback.classic.Logger 2015-04-21 08:28:55.911 DEBUG [main] Service.java:22 - Setup Example 2015-04-21 08:28:55.912 DEBUG [main] Service.java:24 - Example finished虽然这是有效的,但这不是我以前改变过的。 随着时间的推移,这个项目唯一改变的是增加了其他外部罐子。 我不确定如何在另一个外部jar中添加重复/更新/更旧版本的slf4j会影响日志记录,但是任何版本都应该查找logback文件?
- 更新 - 在检查了很多build.xml文件的历史签入后,我发现我们之前实际上有debug =“on”,实际上这个参数可能已经被引入了“off”。
感谢您的帮助。
BR Stefan
I'm having problems with my logging where slf4j doesn't log the filename and row number of the message/stacktrace.
Code:
private static Logger log = LoggerFactory.getLogger(SomeService.class); @Override public void aService(ServiceAdmin sa) throws Exception { log.debug(LoggerFactory.class.toString()); log.debug(log.getClass().getName()); log.debug("Setup Example"); SomeService.setDefault(Example.getInstance()); log.debug("Example finished"); }Log:
2015-04-20 14:47:26.573 DEBUG [main] null:-1 - class org.slf4j.LoggerFactory 2015-04-20 14:47:26.574 DEBUG [main] null:-1 - ch.qos.logback.classic.Logger 2015-04-20 14:47:26.574 DEBUG [main] null:-1 - Setup Example 2015-04-20 14:47:26.575 DEBUG [main] null:-1 - SomeService finishedThis is pars of my logback.xml that relates to this class
<logger name="com.bredband.nexusgw.services"> <level value="debug" /> <appender-ref ref="nexusservice" /> </logger> <appender name="nexusservice" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>/var/log/nexus/nexusjgw/jgw/Service.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <FileNamePattern>/var/log/nexus/nexusjgw/jgw/Service.log.%i </FileNamePattern> <MinIndex>1</MinIndex> <MaxIndex>5</MaxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>200MB</MaxFileSize> </triggeringPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>debug</level> </filter> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] %F:%L - %m%n</Pattern> </layout> </appender>Has anyone seen this before and can point me in the right direction?
BR Stefan
-- Update --
I changed the %F to %C, but that didn't change anything in the logs. Then I tried to set debug = "on" in the javac header in my ant file and now it's logging classname and line number.
2015-04-21 08:28:55.910 DEBUG [main] Service.java:20 - class org.slf4j.LoggerFactory 2015-04-21 08:28:55.911 DEBUG [main] Service.java:21 - ch.qos.logback.classic.Logger 2015-04-21 08:28:55.911 DEBUG [main] Service.java:22 - Setup Example 2015-04-21 08:28:55.912 DEBUG [main] Service.java:24 - Example finishedAlthough this is working, it's not something I've changed before. The only thing that has changed in this project over time is the addition of other external jars. I'm not really sure how adding a duplicate/newer/older version of slf4j in another external jar would affect the logging though, any version should look for the logback file?
-- Update -- After checking alot of historical checkins of the build.xml file I found that we actually had debug = "on" earlier and the problem may actually have been introduced by this parameter beeing set to "off".
Thank you for your help.
BR Stefan
最满意答案
您应首先确保使用调试信息编译应用程序。 如果直接调用javac ,那么它是-g命令行参数。 但是,大多数构建工具(如maven或ant)都有一种特定的方法来提供此参数。
您可能还希望将%F替换为%C ,这应该在没有调试信息的情况下工作。
You should first make sure that you compile your application with debug information. If calling javac directly, then it is the -g command-line parameter. However most build tools (like maven or ant) have a specific way to provide this parameter.
You may also want to replace %F with %C, which should work without the debug information.
更多推荐
发布评论