Logback logging levels are ignored, Spring Boot 2.1.0 - spring

I have been using logback successfully for a while in my Spring Boot applications using Spring Boot 1.5.x and 2.1.x. I use logback-spring.xml on the classpath to configure logback.
After a recent build using Spring Boot version 2.1.0.BUILD_SNAPSHOT, the output to my logs suddenly changed. I am now getting all DEBUG and TRACE levels on all packages (other than my own) e.g. on startup I am swamped with org.apache.* and org.springframework.* logging.
When I try to adjust the logging levels for these packages, the levels are ignored. I.e. the following does not work in limiting the logging:
<logger name="org.apache" level="ERROR"/>
<logger name="org.springframework" level="ERROR"/>
Adjusting the logging level of the root logger also has no affect.
I have ensured that debug=false in application.properties
Note that the log levels for my application still work.
<logger name="com.myapp" level="debug">
<appender-ref ref="MY_FILE" />
<appender-ref ref="CONSOLE" />
</logger>
So it appears that my configuration is indeed found and used to configure logback, but the logging levels for some packages are broken or being overridden?
I have just tested with Spring Boot 2.0.3.RELEASE and I do not have the problem with this version.

Related

Recursive logging from [org.apache.Kafka.clients.networkclient] for appender

I have a spring boot application using log4j2 for logging and want to use Kafka appender . Mentioned all properties in right format in log4j2.xml and properties of Kafka topic ,server and groupid in application.properties
But each time I start my application am facing a error in console logs saying as below
Kafka-producer-network-thread | producer-1 WARN recursive logging from [org.apache.Kafka.clients.networkclient] for appender [mykafkaappendername]
This warning means you should configure your org.apache.kafka Logger to send log events to some other Appender.
You should probably have a proper Log Appender defined and should refer from your logger with appropriate log level and additivity, something like this
<logger name="com" level="INFO" additivity="false">
<appender-ref ref="appenderName"/>
</logger>
<root level="logLevel">
<appender-ref ref="appenderName"/>
</root>

Spring boot - how to reduce log output from specific library?

I am using the library net.iakovlev.timeshape.TimeZoneEngine and it is spewing a lot of [DEBUG] messages on startup which seems to be the default behaviour.
In application.yml I should be able to control logging level with but that's not working somehow.
logging:
level:
net.iakovlev.timeshape: ERROR
Isn't this the correct way to do so?
Set your log configuration file, and add something like this :
...
<logger name="net.iakovlev.timeshape" level ="ERROR" additivity="false">
<!-- YOUR APPENDER -->
<appender-ref ref="CONSOLE" />
</logger>
...

logback-spring.xml loaded before spring boot application configuration properties

I have my own logback base.xml file where i define pre-defined file appenders that are used by different applications.
I want the log directory to be configurable per application with a property in application.properties (log.path) and have a default in case none is provided (/var/log), so i have:
base.xml
<included>
<property name="logPath" value="${logPath:-/var/log}"/>
<appender name="TEST" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/test.log</file>
...
</appender>
logback-spring.xml for spring boot application:
<configuration>
<springProperty scope="context" name="logPath" source="log.path" />
<include resource="base.xml" />
<root level="INFO">
<appender-ref ref="TEST"/>
</root>
</springProfile>
For some reason i end up with two log directories, both /var/log and "log.dir", it seems base.xml is interpreted before spring boot environment is ready.
I'm running spring-boot 1.5.2 comes with logback 1.1.11.
It seems the problem was caused by adding spring-cloud.
During spring cloud's boostraping process, log.dir property is not found and logback creates an logDir_IS_UNDEFINED directory. After the bootstrap process logback is re-initialized with right configuration.
Related spring-cloud issue: issue-197
See Spring Documentation, especially the section about how properties are carried over to logback. Try using logging.path as a property in your application.properties. It should be accessible as LOG_PATH in logback than.
Also the usual way to use the base file is by adding the spring-boot-starter-logging in Maven/Gradle and include it like that:
<include resource="org/springframework/boot/logging/logback/base.xml"/>
I have a similar problem. I use defaultValue. To be honest it's just a smelly workaround.
<springProperty name="configurable.canonical.name" source="canonical.name" defaultValue="${canonical_name}" />
<file>logs/${configurable.canonical.name}.log</file>
canonical_name is defined in default.properties. Maven is going to resolve it during build.

Sentry for logging in Spring

I use Sentry (on premise) for our logging. Recently I started moving to the Spring framework, I am not able to get the logs hit Sentry servers. I tried using log4j and logger (slf4j). In both cases I was not able to make any progress. My assumption is that since I use spring-starter maven dependency, it includes logger by default, while all documentation on Sentry + Java mentions using raven. Probably my log configurations are not read because of this.
Can anybody tell me how can I get sentry working on my Spring project?
EDIT:
Here is my logback.xml which is in classpath.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="Sentry" class="net.kencochrane.raven.logback.SentryAppender">
<dsn>
http://xxx#example.com/sentry/2
</dsn>
</appender>
<root level="error">
<appender-ref ref="Sentry" />
</root>
</configuration>

Suppress internal logging from Gradle tooling API

When I use the Gradle tooling API in my custom plugin, I get a lot of noise at the console, e.g.:
Creating ClassLoader af47d36a-0f9f-40d2-8bc3-b32738455061 from system and [org.gradle.internal.classloader.FilteringClassLoader#5aa153ee].
Creating ClassLoader 0088fcb2-a08b-48a1-92f9-94d18f846340 from org.gradle.internal.classloader.MutableURLClassLoader$Spec#62f1c342 and [org.gradle.internal.classloader.FilteringClassLoader#5aa153ee].
(and half a dozen similar lines), and
Tooling API is using target Gradle version: 2.0.
Connected to the daemon. Dispatching Build{id=b0b916a3-d386-4088-8d00-d321216263ca.1,currentDir=/home/dmoles/Projects/makeproject-new} request.
How can I suppress this? I tried configuring SLF4J to use Log4J in my plugin's build.gradle (I have no idea what it uses by default) and setting an ERROR-level appender for org.gradle in my log4j.xml, but that appears to do nothing.
I then tried adding the following Logback configuration file to my plugin's src/main/resources --
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"/>
<logger name="org.gradle.tooling" level="ERROR" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
-- rebuilt the plugin, refreshed dependencies in the project that uses the plugin, and invoked it again, but I still get all the tooling DEBUG output.
I also tried programmatically reconfiguring the log level but ran into classloader issues:
The following classes appear as argument class and as parameter class, but are defined by different class loader:
ch.qos.logback.classic.Level (defined by 'java.net.URLClassLoader#56464aa5' and 'org.gradle.internal.classloader.MutableURLClassLoader#7e41986c')

Resources