我是Java新手并且必须维护一个spring boot项目。我将日志设置从logback更改为log4j2,因为我想使用JsonLayout来分析使用ElasticSearch的日志。
它在本地工作但在生产中我只获得默认设置,例如像
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!
我的构建脚本是一个Dockerfile,我只使用RUN mvn 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>
基本项目结构是:
- src
- main
- java
- resources
= application.properties
= log4j2.xml
= pom.xml
答案 0 :(得分:0)
我没有意识到我的文件名为Log4j2.xml而不是log4j2.xml(大写L)。我不知道类路径的虚拟文件系统在Linux下是区分大小写的。