I use spring boot 2.3.1 version, and I have an issue with application logs. My logback-spring.xml file as below,
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZZ} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<appender name="APP_LOGGER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/app.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>15</maxHistory>
</rollingPolicy>
<encoder>
<Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZZ} %-5level %-12X{process} %-30([%thread]) %-29logger - %m%n</Pattern>
</encoder>
</appender>
<logger name="com.sample" level="DEBUG" additivity="false"/>
<logger name="org.springframework" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="APP_LOGGER"/>
</root>
</configuration>
My controller is,
package com.sample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
@RestController
public class Controller {
private static final Logger LOGGER = LoggerFactory.getLogger(Controller.class);
@GetMapping("/")
public void greetings(){
LOGGER.info("AAAAA....");
LOGGER.debug("DDDD...");
LOGGER.warn("WWW...");
LOGGER.error("EEEE....")
}
}
I tried adding the below in application.properties file,
logging.level.root=DEBUG
logging.level.org.springframework=INFO
logging.level.com.sample=DEBUG
no luck, and also tried with other alternative approach as below, and added file path logging.file.name=/var/log/app.log
in application.properties
.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<logger name="org.springframework.web" level="INFO"/>
<logger name="com.sample" level="DEBUG"/>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</configuration>
app.log file is creating and I see only spring related logs, not application logs in the app.log file.