Java 生产中未使用弹簧日志设置
我是Java新手,必须维护spring boot项目。我将日志设置从logback更改为log4j2,因为我想使用JsonLayout使用ElasticSearch分析日志 它在本地工作,但在生产中我只获得默认设置,例如Java 生产中未使用弹簧日志设置,java,spring,spring-boot,Java,Spring,Spring Boot,我是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! 我的构建脚本是一个Doc
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
创建包
应用程序属性
#
# 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>
我没有意识到我的文件名为Log4j2.xml,而不是Log4j2.xml(大写L)。我不知道在Linux下类路径的虚拟文件系统是区分大小写的。你能添加
应用程序.properties
文件吗?当然,我已经添加了iti,我找不到log4j配置,你能添加它吗?没有配置。根据文档,如果添加了包,则会自动使用log4j。如果日志配置在类路径上,Spring Boot支持Log4j 2。如果使用启动器组装依赖项,则必须排除Logback,然后包含log4j 2。
- src
- main
- java
- resources
= application.properties
= log4j2.xml
= pom.xml