azi
azi

Reputation: 929

Spring logs not coming machine specific

I am using a spring maven tomcat8 java8 stack. The problem I am facing is that logs are not getting generated on certain machines. I am using slf4j-logback combination for logging. The problem has surfaced when I am trying to move my stack from java7 to java8.

Here is my logback.xml:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <appender name="dal"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/var/log/dal/dal.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>/var/log/dal/dal-%d{yyyy-MM-dd}.log.gz</fileNamePattern>
            <!-- keep 30 days' worth of history -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <append>true</append>
        <encoder>
            <pattern>[%d{HH:mm:ss.SSS} %thread %-5level %C:%L] %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[%d{HH:mm:ss.SSS} %thread %-5level %C:%L] %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="email-appender" class="ch.qos.logback.classic.net.SMTPAppender">
        <to></to>
        <from></from>
        <subject>API Logs - Error while sending notification</subject>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>[%d{HH:mm:ss.SSS} %thread %-5level %C:%L] %msg%n</pattern>
        </layout>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="dal" />
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

Using this, I expect to get logs at two places, at custom location /var/log/dal/dal.log and in catalina.out

Here are a few relevant details of the server where logs are getting generated:

OS:

apache-tomcat-8.0.15 $ uname -a
Linux azi 3.2.0-74-generic #109-Ubuntu SMP Tue Dec 9 16:45:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

MVN:

apache-tomcat-8.0.15 $ mvn -version
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-74-generic", arch: "amd64", family: "unix"

Tomcat:

apache-tomcat-8.0.15 $ bin/version.sh 
Using CATALINA_BASE:   /opt/apache-tomcat-8.0.15
Using CATALINA_HOME:   /opt/apache-tomcat-8.0.15
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.15/temp
Using JRE_HOME:        /usr/lib/jvm/java-8-oracle/
Using CLASSPATH:       /opt/apache-tomcat-8.0.15/bin/bootstrap.jar:/opt/apache-tomcat-8.0.15/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.15
Server built:   Nov 2 2014 19:25:20 UTC
Server number:  8.0.15.0
OS Name:        Linux
OS Version:     3.2.0-74-generic
Architecture:   amd64
JVM Version:    1.8.0_25-b17
JVM Vendor:     Oracle Corporation

JAVA:

apache-tomcat-8.0.15 $ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Permission:

ls -al /var/log/dal/
total 72
drwxrwxrwx 2 root root  4096 Dec 22 19:50 .
drwxrwxrwx 4 root root  4096 Oct 21 09:47 ..
-rw-r--r-- 1 root root 60925 Dec 22 20:38 dal.log

Here are the details for the server where I am not getting any log: OS:

sysadmin@ip-172-30-0-26:/opt/apache-tomcat-8.0.15$ uname -a
Linux ip-172-30-0-26 3.13.0-29-generic #53-Ubuntu SMP Wed Jun 4 21:00:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

MVN:

sysadmin@ip-172-30-0-26:/opt/apache-tomcat-8.0.15$ mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T19:21:42+05:30)
Maven home: /opt/apache-maven-3.2.2
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_25-linux-x64/java-linux-x64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-29-generic", arch: "amd64", family: "unix"

Tomcat:

sysadmin@ip-172-30-0-26:/opt/apache-tomcat-8.0.15$ sudo bin/version.sh 
Using CATALINA_BASE:   /opt/apache-tomcat-8.0.15
Using CATALINA_HOME:   /opt/apache-tomcat-8.0.15
Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.15/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/apache-tomcat-8.0.15/bin/bootstrap.jar:/opt/apache-tomcat-8.0.15/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.15
Server built:   Nov 2 2014 19:25:20 UTC
Server number:  8.0.15.0
OS Name:        Linux
OS Version:     3.13.0-29-generic
Architecture:   amd64
JVM Version:    1.8.0_25-b17
JVM Vendor:     Oracle Corporation

JAVA:

sysadmin@ip-172-30-0-26:/opt/apache-tomcat-8.0.15$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Permission:

sysadmin@ip-172-30-0-26:/opt/apache-tomcat-8.0.15$ ls -al /var/log/dal/
total 8
drwxrwxrwx 2 root root 4096 Dec 22 19:48 .
drwxrwxrwx 4 root root 4096 Dec 22 19:48 ..

Another thing of note can be the fact that when I do System.out.println("msg"), "msg" goes into catalins.out on both servers. And If I change permission of /var/log/dal on the machine logs are getting generated, logs still get generated in catalina.out. So this shouldn't be related to permissions.

I have tried copying war file from one server to another and didn't find any change in behavior. So, this shouldn't be related to maven. Tomcat and Java versions are same. Can this be related to OS?

UPDATE: When I run my application using mvn clean tomcat7:run, I get logs on all servers. So problem seems to be related to tomcat8. I have even tried copying tomcat8 from one server to another. It didn't help.

Upvotes: 4

Views: 146

Answers (2)

azi
azi

Reputation: 929

This was the case of slf4j identifying multiple bindings in classpath. In such scenarios, slf4j chooses the binding pretty much randomly. In my case, this was happening because slf4j-log4j12 binding was available through solr-core. To remove this, I had to exclude this explicitly:

    <dependency>
        <groupId>org.apache.solr</groupId>
        <artifactId>solr-core</artifactId>
        <version>${solr.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Upvotes: 0

Michal
Michal

Reputation: 2423

Please make sure there are no other slf4j bindings on the classpath (e.g., in the tomcat).

Upvotes: 1

Related Questions