Home » Java » Spring log setting not used in production

Spring log setting not used in production

Posted by: admin April 25, 2018 Leave a comment

Questions:

I am Java newbie and have to maintain a spring boot project. I changed the log settings from logback to log4j2 because I would like to use the JsonLayout to analyze the logs with ElasticSearch.

It works locally but in production I only get the default settings, e.g. like

018-04-24 07:50:19.969 INFO 5 --- [pool-3-thread-1] c.e.r.s.SessionService : Session backup completed: 0 failed, 0 succeeded!

My build script is a Dockerfile, where I just use RUN mvn package to create the package.

Application.properties

#
# Spring Webservice Configuration 
#
server.port:9002
management.port:9001

#
# Profile
#
spring.profiles.active:production

#
# Rule Server Configuration
#
ruleServer.uniqueName:localhost

#
# REST endpoints
#
easierlife.events.endpoint:/api/households/%s/events?auth_token=%s
easierlife.session.endpoint:/api/sessions

orbit.clusterMode:local
orbit.clusterName:easierlife-rs
orbit.nodeName:host

#
# Database configuration
#
spring.datasource.url=...
spring.datasource.username=...
spring.datasource.password=...
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.testOnBorrow=true
spring.datasource.testWhileIdle=true
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.validationQuery=SELECT 1

# Spring JPA config:
spring.jpa.hibernate.ddl-auto:update
spring.jpa.hibernate.naming-strategy:org.hibernate.cfg.EJB3NamingStrategy
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.show-sql:false

Log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
            <JsonLayout eventEol="true" compact="true" stacktraceAsString="true" />
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="ConsoleAppender" />
        </Root>
    </Loggers>
</Configuration>

The basic project structure is:

- src
  - main
    - java
      - resources
        = application.properties
        = log4j2.xml
 = pom.xml
Answers: