I have following logback configuration for spring boot. Whenever I add {PID: } in log-pattern: property of application.yml, I get the warning "No appenders present..." highlighted in the logs below. What causes this warning and how to fix it?
The Specific Warning From The Logs Below:
23:17:25,356 |-WARN in Logger[org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertyResolver$DefaultResolver] - No appenders present in context [default] for logger [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertyResolver$DefaultResolver].
Console Logs:
23:17:25.021 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@c2e465d
23:17:25,335 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@11478ace - Adding [jar:file:/C:/Users/sibajpai/.m2/repository/org/springframework/boot/spring-boot/2.7.7/spring-boot-2.7.7.jar!/org/springframework/boot/logging/logback/defaults.xml] to configuration watch list.
23:17:25,336 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@25c79f4d - URL [jar:file:/C:/Users/sibajpai/.m2/repository/org/springframework/boot/spring-boot/2.7.7/spring-boot-2.7.7.jar!/org/springframework/boot/logging/logback/defaults.xml] is not of type file
23:17:25,338 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word clr with class [org.springframework.boot.logging.logback.ColorConverter]
23:17:25,338 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word wex with class [org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter]
23:17:25,338 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word wEx with class [org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter]
23:17:25,339 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.catalina.startup.DigesterFactory] to ERROR
23:17:25,340 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating ERROR level on Logger[org.apache.catalina.startup.DigesterFactory] onto the JUL framework
23:17:25,340 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.catalina.util.LifecycleBase] to ERROR
23:17:25,340 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating ERROR level on Logger[org.apache.catalina.util.LifecycleBase] onto the JUL framework
23:17:25,340 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.coyote.http11.Http11NioProtocol] to WARN
23:17:25,340 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating WARN level on Logger[org.apache.coyote.http11.Http11NioProtocol] onto the JUL framework
23:17:25,340 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.sshd.common.util.SecurityUtils] to WARN
23:17:25,340 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating WARN level on Logger[org.apache.sshd.common.util.SecurityUtils] onto the JUL framework
23:17:25,340 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.tomcat.util.net.NioSelectorPool] to WARN
23:17:25,340 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating WARN level on Logger[org.apache.tomcat.util.net.NioSelectorPool] onto the JUL framework
23:17:25,340 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.eclipse.jetty.util.component.AbstractLifeCycle] to ERROR
23:17:25,340 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating ERROR level on Logger[org.eclipse.jetty.util.component.AbstractLifeCycle] onto the JUL framework
23:17:25,341 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate.validator.internal.util.Version] to WARN
23:17:25,341 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating WARN level on Logger[org.hibernate.validator.internal.util.Version] onto the JUL framework
23:17:25,341 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.boot.actuate.endpoint.jmx] to WARN
23:17:25,341 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating WARN level on Logger[org.springframework.boot.actuate.endpoint.jmx] onto the JUL framework
23:17:25,341 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@11478ace - Adding [jar:file:/C:/Users/sibajpai/.m2/repository/org/springframework/boot/spring-boot/2.7.7/spring-boot-2.7.7.jar!/org/springframework/boot/logging/logback/console-appender.xml] to configuration watch list.
23:17:25,341 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@25c79f4d - URL [jar:file:/C:/Users/sibajpai/.m2/repository/org/springframework/boot/spring-boot/2.7.7/spring-boot-2.7.7.jar!/org/springframework/boot/logging/logback/console-appender.xml] is not of type file
23:17:25,342 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
23:17:25,343 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
23:17:25,345 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
**23:17:25,356 |-WARN in Logger[org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertyResolver$DefaultResolver] - No appenders present in context [default] for logger [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertyResolver$DefaultResolver].**
23:17:25,356 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
23:17:25,358 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [PRIMARY_FILE]
23:17:25,361 |-INFO in c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@253954107 - setting totalSizeCap to 5 MB
23:17:25,362 |-INFO in c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@253954107 - Archive files will be limited to [500 KB] each.
23:17:25,364 |-INFO in c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@253954107 - No compression will be used
23:17:25,364 |-INFO in c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@253954107 - Will use the pattern log/primary/log_%d{dd-MM-yyyy_hh-mm-ss-aa}__%i.txt for the active file
23:17:25,365 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@a182f32 - The date pattern is 'dd-MM-yyyy_hh-mm-ss-aa' from file name pattern 'log/primary/log_%d{dd-MM-yyyy_hh-mm-ss-aa}__%i.txt'.
23:17:25,365 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@a182f32 - Roll-over every second.
23:17:25,370 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@a182f32 - Setting initial period to Thu Jan 12 23:17:04 IST 2023
23:17:25,371 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
23:17:25,372 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[PRIMARY_FILE] - Active log file name: log/primary/log.log
23:17:25,372 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[PRIMARY_FILE] - File property is set to [log/primary/log.log]
23:17:25,373 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
23:17:25,374 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@565ef2fc - Propagating INFO level on Logger[ROOT] onto the JUL framework
23:17:25,374 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
23:17:25,374 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [PRIMARY_FILE] to Logger[ROOT]
23:17:25,374 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
23:17:25,374 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@506c4f4c - Registering current configuration as safe fallback point
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.7)
2023-01-12 23:17:25.418 INFO 16844 --- [ restartedMain] ingBootFeaturesLoggingSimple4Application : Starting SpringBootFeaturesLoggingSimple4Application using Java 11.0.12 on INLEN8520055550 with PID 16844 (C:\Users\sibajpai\eclipse-workspace5\spring-boot-features-logging-simple-4\target\classes started by sibajpai in C:\Users\sibajpai\eclipse-workspace5\spring-boot-features-logging-simple-4)
2023-01-12 23:17:25.419 INFO 16844 --- [ restartedMain] ingBootFeaturesLoggingSimple4Application : No active profile set, falling back to 1 default profile: "default"
2023-01-12 23:17:25.452 INFO 16844 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-01-12 23:17:25.792 INFO 16844 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2023-01-12 23:17:25.805 INFO 16844 --- [ restartedMain] ingBootFeaturesLoggingSimple4Application : Started SpringBootFeaturesLoggingSimple4Application in 0.773 seconds (JVM running for 1.535)
2023-01-12 23:17:25.807 WARN 16844 --- [ restartedMain] ingBootFeaturesLoggingSimple4Application : message
23:17:25,807 |-INFO in c.q.l.co.rolling.helper.RenameUtil - Renaming file [log\primary\log.log] to [log\primary\log_12-01-2023_11-17-04-PM__0.txt]
23:17:25,809 |-INFO in c.q.l.core.rolling.helper.TimeBasedArchiveRemover - first clean up after appender initialization
23:17:25,811 |-INFO in c.q.l.core.rolling.helper.TimeBasedArchiveRemover - Multiple periods, i.e. 336 periods, seem to have elapsed. This is expected at application start.
23:17:25,815 |-INFO in c.q.l.core.rolling.helper.TimeBasedArchiveRemover - deleting C:\Users\sibajpai\eclipse-workspace5\spring-boot-features-logging-simple-4\log\primary\log_12-01-2023_11-17-04-PM__0.txt
23:17:25,895 |-INFO in c.q.l.core.rolling.helper.TimeBasedArchiveRemover - Removed 0 Bytes of files
Spring Boot Application Class:
package com.learning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootFeaturesLoggingSimple4Application implements CommandLineRunner {
private Logger logger = LoggerFactory.getLogger(SpringBootFeaturesLoggingSimple4Application.class);
public static void main(String[] args) {
SpringApplication.run(SpringBootFeaturesLoggingSimple4Application.class, args);
}
@Override
public void run(String... args) throws Exception {
logger.warn("message");
}
}
application.yml
applicationname:
logging:
primary-file:
clean-history-on-start: false
history-name-pattern: log/primary/log_%d{dd-MM-yyyy_hh-mm-ss-aa}__%i.txt
log-charset: UTF-8
# warning comes after adding ${PID: } in below line
log-pattern: '${PID: } - %m%n'
max-history: 10
max-size: 500KB
name: log/primary/log.log
threshold-level: WARN
total-size-cap: 5MB
root:
level: INFO
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<springProperty name="ROOT_LEVEL" source="applicationname.logging.root.level" defaultValue="INFO" />
<!-- primary file appender properties -->
<springProperty name="PRIMARY_FILE_NAME" source="applicationname.logging.primary-file.name" defaultValue="${LOG_FILE:-log/primary/log.log}" />
<springProperty name="PRIMARY_FILE_THRESHOLD_LEVEL" source="applicationname.logging.primary-file.threshold-level" defaultValue="WARN" />
<springProperty name="PRIMARY_FILE_HISTORY_NAME_PATTERN" source="applicationname.logging.primary-file.history-name-pattern" defaultValue="${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-log/primary/%d{dd-MM-yyyy_hh-mm-aa,aux}/log_%d{dd-MM-yyyy_hh-mm-ss-aa}__%i.txt}" />
<springProperty name="PRIMARY_FILE_CLEAN_HISTORY_ON_START" source="applicationname.logging.primary-file.clean-history-on-start" defaultValue="${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}" />
<springProperty name="PRIMARY_FILE_MAX_SIZE" source="applicationname.logging.primary-file.max-size" defaultValue="${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}" />
<springProperty name="PRIMARY_FILE_TOTAL_SIZE_CAP" source="applicationname.logging.primary-file.total-size-cap" defaultValue="${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-2GB}" />
<springProperty name="PRIMARY_FILE_MAX_HISTORY" source="applicationname.logging.primary-file.max-history" defaultValue="${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-200}" />
<springProperty name="PRIMARY_FILE_LOG_PATTERN" source="applicationname.logging.primary-file.log-pattern" defaultValue="${FILE_LOG_PATTERN:-%d{dd-MM-yyyy hh:mm:ss.SSS aa} ${LOG_LEVEL_PATTERN:%5p} ${PID: } ---%replace( USER:%X{username}){' USER:$', ''} [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}}" />
<springProperty name="PRIMARY_FILE_LOG_CHARSET" source="applicationname.logging.primary-file.log-charset" defaultValue="${FILE_LOG_CHARSET}" />
<!-- primary file appender] -->
<appender name="PRIMARY_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${PRIMARY_FILE_NAME}</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${PRIMARY_FILE_THRESHOLD_LEVEL}</level>
</filter>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${PRIMARY_FILE_HISTORY_NAME_PATTERN}</fileNamePattern>
<cleanHistoryOnStart>${PRIMARY_FILE_CLEAN_HISTORY_ON_START}</cleanHistoryOnStart>
<maxFileSize>${PRIMARY_FILE_MAX_SIZE}</maxFileSize>
<totalSizeCap>${PRIMARY_FILE_TOTAL_SIZE_CAP}</totalSizeCap>
<maxHistory>${PRIMARY_FILE_MAX_HISTORY}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${PRIMARY_FILE_LOG_PATTERN}</pattern>
<charset>${PRIMARY_FILE_LOG_CHARSET}</charset>
</encoder>
</appender>
<root level="${ROOT_LEVEL}">
<appender-ref ref="CONSOLE" />
<appender-ref ref="PRIMARY_FILE" />
</root>
</configuration>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.learning</groupId>
<artifactId>spring-boot-features-logging-simple-4</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-features-logging-simple-4</name>
<description>spring learning</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>