1

I am running a POC to see the impact of migrating our j2ee applications to logback. I spent some time on the official website and apparently, the only change beside new jars was the logback.xml file. Unfortunatly doesn't look to be enough, the deployment works and the log file is created as well, but nothing is logged (empty).

my code has the following statements

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

private static final Logger log = LoggerFactory.getLogger(CustomerServiceBean.class);
log.debug("test Log Back - customer ID  " + input.getCustomerId());

pom.xml has now the following

<dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version>0.9.18</version>
 </dependency>

logback.xml (created using web utility from the official website)

<configuration>
   <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
   <!--See also http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
   <File>/var/log/dcs-3/dcs3.log</File>
   <encoder>
     <pattern>%d{ABSOLUTE} %5p %c{1}:%L - %m%n</pattern>
   </encoder>
   <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
     <maxIndex>1</maxIndex>
     <FileNamePattern>/var/log/dcs-3/dcs3.log.%i</FileNamePattern>
   </rollingPolicy>
   <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
     <MaxFileSize>1MB</MaxFileSize>
   </triggeringPolicy>
 </appender>
 <logger name="com.lgi.dcs" level="DEBUG" />
 <root level="debug">
   <appender-ref ref="file"/>
 </root>
</configuration>

any idea? thanks

UPDATE
I made few more changes as suggested. The issue is still open, however I was able to obtain more information.
I logged an ERROR instead of a simple DEBUG. I removed all log4j jars or dependencies from the project and added the log4j-bridge. I changed the logback.xml with one more generic taken from another post and used an appender on the console in addition to the file.

Now in my IDE looks like the Logger instance is implemented by ch.qos.locback.classic.Logger. The log file is still empty, but if I delete it than is recreated during server start-up. On the server log I can now see the my test message like:

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [zip:/opt/oracle-soa/user_projects/domains/osb/servers/AdminServer/tmp/_WL_user/dcs3-ear-3/9yhkv9/APP-INF/lib/logback-classic-0.9.18.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [zip:/opt/oracle-soa/user_projects/domains/osb/servers/AdminServer/tmp/_WL_user/dcs3-ear-3/9yhkv9/APP-INF/lib/logback-classic-0.9.18.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. 11:40:17.902 [[ACTIVE] ExecuteThread: '12' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR c.l.d.s.customer.CustomerServiceBean - test Log Back - customer ID 6107576

which some how makes me think about the log4j within weblogic perhaps.

4

3 回答 3

0

Log4jLoggerAdapter 存在于 SLF4J Log4J 包装器实现中。很可能您的类路径中有slf4j-log4j12,因此 SLF4J 同时有 2 个日志记录后端 impl(LogBack 和 Log4J Impl)

另一个答案是提到 log4j-over-slf4j,它用于将调用重定向到 Log4J 以使用 SLF4J,如果您使用 LogBack,它应该存在(当然,如果您希望 log4j 消息通过 SLF4J)

于 2013-08-08T06:22:25.140 回答
0

正如您上面提到的,记录器工厂返回 log4j 的实例而不是 logback。这意味着您仍然在类路径上有 log4j。它可以直接提供并错误地留在那里,或者它作为您正在使用的库的依赖项。如果您使用的是 maven,请尝试调查 EFFECTIVE POM 是否存在 log4j,并排除它们。否则你必须手动完成。如果您会发现该依赖项,删除它应该可以解决问题。

您应该寻找的 jar 可能是 slf4j bridge log4j-over-slf4jjcl-over-slf4j也可能相关。

于 2013-08-08T05:44:35.447 回答
0

对于 Java EE 应用程序,如果您的应用程序直接写入文件系统(因为这会在多 JVM 容器上中断),那么您就违反了规范。

这基本上排除了战内/入耳式记录。

而是考虑使用 slf4j java.util.logging 桥,让容器捕获和管理日志记录。

于 2016-10-14T15:20:25.410 回答