Suppress internal logging from Gradle tooling API - gradle

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')

Related

Java Springboot Gradle project how to write log to cloudwatch?

I have configured log4j2 in my gradle project to write the log to a local file. The log4j2.xml file is written as follow:
<Configuration>
<appender name="cloud-watch" class="io.github.dibog.AwsLogAppender">
<awsConfig>
<credentials>
<accessKeyId>XXXXX</accessKeyId>
<secretAccessKey>XXXXXX</secretAccessKey>
</credentials>
<region>us-east-2</region>
</awsConfig>
<createLogGroup>true</createLogGroup>
<queueLength>100</queueLength>
<groupName>SpringLog</groupName>
<streamName>StreamName</streamName>
<dateFormat>yyyyMMdd_HHmm</dateFormat>
<layout>
<pattern>[%thread] %-5level %logger{35} - %msg %n</pattern>
</layout>
</appender>
<Loggers>
<Root level="ALL">
<AppenderRef ref="cloud-watch"/>
</Root>
</Loggers>
</Configuration>
Here I am firstly getting an error "Unable to locate appender "cloud-watch". Also the logging to the cloudwatch is also not working.
Can any one please correct me what I am doing wrong. Your help is much appreciated. I tried consoling the log and it works fine.
Can anyone suggest on how to do logging from springboot gradle project to aws cloudwatch?
This is not a valid Log4j2 configuration. Log4j2 uses plugins and the class name of appenders, filters, layouts, etc is never specified in the configuration.
I found an example configuration similar to yours at https://github.com/dibog/cloudwatch-logback-appender. Note that the name of the project is cloudwatch-logback-appender, so this appender is designed to work with Logback, not Log4j2.

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 logging levels are ignored, Spring Boot 2.1.0

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.

Spring Profile not available in Logback when run via Maven

I've set up logback.xml to select which appender to use based on the active Spring profile. The technique works perfectly when I run the app using
java -jar -Dspring.profiles.active=local path/to/target/application.war
but not when I run it using the Spring Boot Maven Plugin, e.g.
mvn spring-boot:run -Drun.profiles=local
Here's the relevant section of the logback.xml
<root level="INFO">
<if condition='"${spring.profiles.active}".contains("local")'>
<then>
<appender-ref ref="CONSOLE"/>
</then>
<else>
<appender-ref ref="FILE"/>
</else>
</if>
</root>
I will note that the profile does show up correctly in the application itself, just isn't available when processing logback.xml.
The problem also manifests when running from the IntelliJ IDE.
Is there another way to use the Maven Spring Boot Plugin to cause the profile to be visible to the logback.xml parser, and would it work for IntelliJ, as well?
Have you tried to configure logback through logback-spring extension?
In your case logback-spring.xml could look like this:
<?xml version="1.0" encoding="UTF-8"?>
<include resource="org/springframework/boot/logging/logback/base.xml"/><!-- include this config if you want to use spring-boot's built-in appenders -->
<configuration>
<root level="INFO">
<springProfile name="local">
<appender-ref ref="CONSOLE"/>
</springProfile>
<springProfile name="otherprofile">
<appender-ref ref="FILE"/>
</springProfile>
</root>
</configuration>
More information about available options in logback-spring extensions:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html#boot-features-logback-extensions

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>

Resources