I have configured anonymizer for my logger:
--> logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<appender name="CUSTOM_CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${CONSOLE_LOG_THRESHOLD}</level>
</filter>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="util.CustomPatternLayout">
<anonymize>someFieldName</anonymizeJson>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>${CONSOLE_LOG_CHARSET}</charset>
</layout>
</encoder>
</appender>
<root>
<appender-ref ref="CUSTOM_CONSOLE"/>
</root>
<logger name="root" level="INFO"/>
</configuration
Locally, everything works fine, but when it is deployed to Azure in Docker container, it seems to ignore my logback file.
I tried to use this file for configuration with names: logback.xml, logback-spring.xml
I tried to specify configuration for docker container
-Dlogback.configurationFile=src/main/resources/logback-spring.xml
nd also with this in application.yml
I have application insights agent, maybe it is broking my logging?
logging:
config: classpath:logback.xml
Locally, everything is ok but on Azure I got issues.
tried to use this file for configuration with names: logback.xml, logback-spring.xml I tried to specify configuration for docker container
-Dlogback.configurationFile=src/main/resources/logback-spring.xml
nd also with this in application.yml
logback.xml
is not included in the final JAR file and specify its location externally when running the Spring Boot application.
-Dlogback.configurationFile
system property. This property tells Logback where to find the configuration file.java -Dlogback.configurationFile=file:/full_path/logback.xml -jar app.jar
Deploy the Spring Boot JAR without the logback.xml
file included in it. Check that the logback.xml
file is present in the same directory as the JAR file on the Azure server.
Add Dependencies:
pom.xml
, add the following dependencies for Application Insights:<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-runtime-attach</artifactId>
<version>3.4.18</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-core</artifactId>
<version>3.4.18</version>
</dependency>
Configuration Logback:
logback.xml
file in your project (if you haven’t already).Reference:
If possible try to use the below version for the java if the above approach is not satisfied.