springboot upgrade from 1.2.1 to 1.3.3 logback issue - spring

I have upgraded springboot version from 1.2.1 to 1.3.3 but i am facing some logback problems:
with version 1.2.1 it works perfectly fine:
Exception:
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter#14:16 - no applicable action for [pattern], current ElementPath is [[configuration][appender][layout][pattern]]
ERROR in ch.qos.logback.core.joran.action.NestedBasicPropertyIA - Unexpected aggregationType AS_BASIC_PROPERTY_COLLECTION
ERROR in ch.qos.logback.core.joran.spi.Interpreter#23:66 - no applicable action for [staticField], current ElementPath is [[configuration][appender][layout][staticField]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#24:24 - no applicable action for [key], current ElementPath is [[configuration][appender][layout][staticField][key]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter#25:26 - no applicable action for [value], current ElementPath is [[configuration][appender][layout][staticField][value]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:151)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:195)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:65)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:277)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:255)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:224)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:200)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
at com.xx.yy.zz.hh.Application.main(Application.java:14)
Logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>BlueBerry %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="AMQP" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
<!-- <filter class="com.xx.yy.util.LogsFilter" />-->
<layout class="me.moocar.logbackgelf.GelfLayout">
<pattern>BlueBerry %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<shortMessageLayout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</shortMessageLayout>
<useLoggerName>true</useLoggerName>
<useThreadName>true</useThreadName>
<useMarker>true</useMarker>
<includeFullMDC>true</includeFullMDC>
<fieldType>requestId:long</fieldType>
<staticField class="me.moocar.logbackgelf.Field">
<key>_facility</key>
<value>GELF</value>
</staticField>
</layout>
<host>srv173.xx.yy.com</host>
<port>XXXX</port>
<username>guest</username>
<password>guest</password>
<exchangeType>direct</exchangeType>
<exchangeName>amq.direct</exchangeName>
<applicationId>RabbitMq-IT-SE</applicationId>
<routingKeyPattern>logs</routingKeyPattern>
<generateId>true</generateId>
<charset>UTF-8</charset>
<durable>true</durable>
<abbreviation>36</abbreviation>
<deliveryMode>NON_PERSISTENT</deliveryMode>
<declareExchange>true</declareExchange>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<!-- <appender-ref ref="GELF TCP APPENDER"/>-->
<appender-ref ref="AMQP"/>
</root>
</configuration>
I tried using Dependencies Management as mentioned in this question but it did not work for me:
spring-boot upgrade from 1.3.2 to 1.3.3: logback issue

Is upgrading to Spring Boot 1.3.4 an option ?
Although not exactly the same symptoms, it still points to logback dependency issues in 1.3.3. It seems to be fixed in 1.3.4: https://github.com/logstash/logstash-logback-encoder/issues/153
Ugrading to Spring Boot 1.3.4 fixed this for me

Related

Trying to connect to Sentry ver 1.7.30 with Spring Boot ver 1.5.7

Hi I am getting confused with setting up old version of Sentry(ver 1.7.30) with current Spring Boot project(ver 1.5.7).
Here's my part of Gradle:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-logging")
compile("org.springframework.boot:spring-boot-starter-actuator")
...
implementation 'io.sentry:sentry-spring:1.7.30'
implementation 'io.sentry:sentry-logback:1.7.30'
}
application-local.yml
sentry:
dsn: https://dsnPath
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- sentry -->
<configuration>
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="FILE"/>
<appender-ref ref="Sentry" />
</root>
</configuration>
When I run the project on local laptop, I can see some exception logs on console but they don't show up on Sentry. One thing I'm sure is..there's log4j2-spring.xml before I created logback-spring.xml file only for Sentry and this might be a problem?
(I followed the instruction on official page - https://docs.sentry.io/platforms/java/legacy/spring/ - and it didn't work. Maybe I made mistake regarding resolver.)
Thanks in advance!

issues with logback using springboot

please help me...I'm new to programming so please dumb it down for me.
I'm building a project and below is my code. however, I keep getting an error message that's included below.
Now I saw a previous thread that says I should use an earlier version of logback, but I dont now how to change it to the previous version. Can someone please walk me through it. I would really appreciate an fix to my problem so that I can move forward.
Thanks
Error message:
Logging system failed to initialize using configuration from 'null' java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [appender_name_IS_UNDEFINED]. Did you define it below instead of above in the configuration file? ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.
My CODE:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<springProperty scope="context" name="appender_name" source="app.logging-to" />
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) [PID: %clr(${PID:- }){magenta}] %clr(-){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx
</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>Cloud-Panel-Logs.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>Cloud-Panel-Logs.%d{yyyy-MM}.log</fileNamePattern>
<maxHistory>6</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) [PID: %clr(${PID:- }){magenta}] %clr(-){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wEx
</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="ASYNC_CONSOLE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="${appender_name}" />
<discardingThreshold>0</discardingThreshold>
<queueSize>100000</queueSize>
<includeCallerData>false</includeCallerData>
<neverBlock>false</neverBlock>
</appender>
<root level="INFO">
<appender-ref ref="ASYNC_CONSOLE" />
</root>
</configuration>
I've tried installing every other extension for spring and problems still exist...

Logback configuration error when running Spring boot on linux vm - windows vm is ok

I have a spring boot app hosted on an azure app service which starts fine on a windows vm but on linux vm I get this logback error (scroll down for full stacktrace):
2022-08-09T21:04:41.0995698 Caused by: java.lang.IllegalStateException: Logback configuration error detected:
2022-08-09T21:04:41.0995738 ERROR in c******#3:104 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
Using:
org.springframework.boot:spring-boot:2.3.7.RELEASE
ch.qos.logback:logback-core:1.2.3
I'm just putting this out there, in case anyone has seen this before. Next steps for me would be to either set-up remote debugger to azure or set-up a local linux vm to test.
logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context" name="instrumentationKey" source="appinsights.instrumentationkey"/>
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
<springProfile name="logging-azure">
<appender name="aiAppender" class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender">
<instrumentationKey>${instrumentationKey}</instrumentationKey>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender>
</springProfile>
<!-- Initial Parent Folder -->
<variable name="logfilePath" value="br-proposition-logs"/>
<include resource="standard-logback-config.xml"/>
<springProfile name="logging-local">
<root level="ERROR">
<appender-ref ref="STDOUT"/>
<appender-ref ref="LOG-FILE"/>
</root>
</springProfile>
<springProfile name="logging-azure">
<root level="ERROR">
<appender-ref ref="aiAppender"/>
<appender-ref ref="LOG-FILE"/>
</root>
</springProfile>
</configuration>
and standard-logback-config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<included>
<variable name="fileName" value="br-proposition"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%X{proposition.requestId}] %-5level %logger %marker %msg%n</pattern>
</encoder>
</appender>
<appender name="LOG-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logfilePath}/${fileName}.log</file>
<rollingPolicy class="com.lv.gi.traps.common.logging.TrapsSizeAndTimeBasedRollingPolicy">
<FileNamePattern>${logfilePath}/%d{yyyy-MM-dd,aux}/${fileName}.%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<maxFileSize>20MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<pattern>%d [${HOSTNAME}:%X{proposition.requestId}] %-5level %logger %marker %msg%n</pattern>
</encoder>
</appender>
</included>
Full stacktrace:
2022-08-09T21:04:41.0994993 Exception in thread "main" java.lang.reflect.InvocationTargetException
2022-08-09T21:04:41.0995272 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2022-08-09T21:04:41.099543 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2022-08-09T21:04:41.0995473 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2022-08-09T21:04:41.0995512 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
2022-08-09T21:04:41.0995549 at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
2022-08-09T21:04:41.0995588 at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
2022-08-09T21:04:41.0995625 at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
2022-08-09T21:04:41.0995661 at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
2022-08-09T21:04:41.0995698 Caused by: java.lang.IllegalStateException: Logback configuration error detected:
2022-08-09T21:04:41.0995738 ERROR in c****#3:104 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]**
2022-08-09T21:04:41.0995776 ERROR in c******#6:41 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
2022-08-09T21:04:41.0995815 ERROR in c******#7:115 - no applicable action for [appender], current ElementPath is [[configuration][springProfile][appender]]
2022-08-09T21:04:41.0995854 ERROR in c******#8:33 - no applicable action for [instrumentationKey], current ElementPath is [[configuration][springProfile][appender][instrumentationKey]]
2022-08-09T21:04:41.0995894 ERROR in c******#9:75 - no applicable action for [filter], current ElementPath is [[configuration][springProfile][appender][filter]]
2022-08-09T21:04:41.0995933 ERROR in c******#10:24 - no applicable action for [level], current ElementPath is [[configuration][springProfile][appender][filter][level]]
2022-08-09T21:04:41.0995971 ERROR in c******#20:41 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
2022-08-09T21:04:41.0996017 ERROR in c******#21:29 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
2022-08-09T21:04:41.0996057 ERROR in c******#22:41 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
2022-08-09T21:04:41.0996095 ERROR in c******#23:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
2022-08-09T21:04:41.0996135 ERROR in c******#27:41 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
2022-08-09T21:04:41.0996174 ERROR in c******#28:29 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
2022-08-09T21:04:41.099624 ERROR in c******#29:45 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
2022-08-09T21:04:41.0996281 ERROR in c******#30:43 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
2022-08-09T21:04:41.0996321 at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
2022-08-09T21:04:41.0996359 at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
2022-08-09T21:04:41.0996397 at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
2022-08-09T21:04:41.0996434 at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
2022-08-09T21:04:41.0996471 at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:306)
2022-08-09T21:04:41.0996509 at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)
2022-08-09T21:04:41.0996547 at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
2022-08-09T21:04:41.0996589 at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
2022-08-09T21:04:41.0996628 at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
2022-08-09T21:04:41.0996666 at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
2022-08-09T21:04:41.0996705 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
2022-08-09T21:04:41.0996742 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
2022-08-09T21:04:41.099678 at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
2022-08-09T21:04:41.0996818 at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
2022-08-09T21:04:41.0996856 at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
2022-08-09T21:04:41.0996897 at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
2022-08-09T21:04:41.0996934 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
2022-08-09T21:04:41.0996971 at com.lv.gi.propositionengine.PropositionEngineInitializer.initialise(PropositionEngineInitializer.java:20)
2022-08-09T21:04:41.0997009 at com.lv.gi.br.propositionengine.AppPropositionEngineApplication.main(AppPropositionEngineApplication.java:28)
2022-08-09T21:04:41.0997074 ... 8 more
This issue was fixed by renaming logback.xml to logback-spring.xml I’m not able to explain why this was only necessary when the jar ran on Linux but not on windows. It works now on both OS’s.
The logback-spring.xml name is recommended by Spring in the spring boot documentation ensuring spring beans required by logback are initialised in time.

How to clear log file before executing spring boot app?

I have been using the default spring logging configuration where I only specify filename in the application.properties file.
logging.file.name=app.log
But this by default appends logs when I start the application from cmd line "java -jar abc.jar"
I tried to search for the property which clears the file before starting application every time but couldn't find it. How should I clear the log file before starting the app?
Spring Boot uses Logback framework as as a default Logger.
You can use environnement variable via application.properties file to set some logging properties but logback xml configuration provides more powerfull features.
When a file in the classpath has one of the following names, Spring Boot will automatically load it over the default configuration:
logback-spring.xml
logback.xml
logback-spring.groovy
logback.groovy
So You can just put the code snippet below in src/main/resources/logback-spring.xml file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>app.log</file>
<append>false</append>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="FILE" />
<appender-ref ref="Console" />
</root>
</configuration>
The line <append>false</append> does the job.
if you wanna log more information than those avaible with the encoder pattern <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> please check logback documention https://logback.qos.ch/manual/layouts.html#logback-access

Logging pattern in spring boot application

How do I set the logging file pattern to something like server.log.2017-12-22.gz?
As of now in my application.properties file, I have set the logging pattern to:
logging.pattern.file= "%d{yyyy-MM-dd } [%thread] %-5level %logger{36} - %msg%n"
logging.file=/var/opt/VS_Logs/server.log
But I need to store the files in the following format: server.log.2017-12-22.gz
As soon as you want custom rolling and triggering policies, you can no longer rely on Spring boot's logging configuration, and you have to use the vendor specific logging configuration. Here is an example using Logback and a TimeBasedRollingPolicy:
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>server.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>server.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd } [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="FILE" />
</root>
</configuration>
Logback will automatically gzip it when you use the .gz extension. If you save this file as logback.xml and put it on your classpath, Spring boot will automatically detect it, otherwise, you can use the logging.config property:
logging.config=classpath:logback.xml

Resources