Reactive Mongo Repository Logging - spring-boot

With Spring Boot 2.0.0.M7, I want to log the queries generated by ReactiveMongoRepository. I have tried the following configs,
logging.level.org.springframework.data.mongodb.core.MongoTemplate: DEBUG
org.springframework.data.document.mongodb: DEBUG
logging.level.org.springframework.data.document.mongodb: DEBUG
log4j.category.org.springframework.data.document.mongodb: DEBUG
but still, the queries are not logged. Any more configuration needed? Thanks

Please use reactiveMongoTemplate configuration
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG

Related

How to know what log levels used in production spring boot application?

I am wondering if there is a way to know what are the logging levels set in spring boot application, which is running on production. I know I can check some logging level statements in application.yml. But I am not sure if it is edited after starting the application.
So, I want to confirm what logging levels are used in the application without stopping or restarting.
Can you provide inputs on this?
If actuators are enabled on your project you can call the /actuator/loggers endpoint:
$curl 'http://localhost:8080/actuator/loggers' -i -X GET
For more reference

How to log the trace id using Springboot custom filters

I have few custom filters in my Springboot Webflux API. This project has been activated with Spring Sleuth, however, these filters are not logging the trace and span ids in the log messages.
I made sure that the order was set properly for these filters.
Example:
2020-03-23 12:53:18.895 -2020-03-23 12:53:18.895 INFO [my-spring-boot,,,] 9569 --- [ctor-http-nio-3] c.d.a.f.test.myTestEnvWebFilter : Reading data from header
Can someone please provide your insights on this?
It might be due to the default sampler percentage configuration, take a look at this article for an example:
https://www.baeldung.com/tracing-services-with-zipkin

How to turn of hibernate-validator DEBUG logger

I add hibernate-validator(6.0.9.Final) to my spring (not spring boot) maven project and work perfectly, but cause lot of(~3000 row) DEBUG log. How to off this log?
I tried these, but didn't work:
logging.level.org.hibernate=info
log4j.logger.org.hibernate=info
The log level of Hibernate Validator is (obviously) not DEBUG by default so you must have something in your application classpath setting the log level to DEBUG.
Hibernate Validator is using JBoss Logging which uses log4j under the hood so log4j.logger.org.hibernate.validator=info in your log4j.properties should work.
But considering it shouldn't have been set to DEBUG in the first place, I'm wondering if you have something in your classpath overriding your log configuration.
I suspect either you or a dependency have enabled DEBUG logging for org.hibernate to see the queries or something similar and this is this setting you should find and remove.
Set the log4j properties as
log4j.logger.org.hibernate.validator=info
also set the show_sql =false to avoid the query printing on the console.

Spring Boot Logging Configuration

Is there a way to disable Spring boot logs and print only the logs which i give in the program using logger.info or logger.debug statements. I mean i want only the log statements which i had given in the program to be logged and nothing else. I use the default logging system given by spring boot. If required i can change to log4j or log4j2 as well. Using spring-boot version 1.2.7.
In other way, putting forward , like logging.level.org.springframework can be used to log spring related logs ,is there a way like logging.level.applicationlevel to get application(Java logger statement) logs alone
You can configure your logging in your application.properties like below:
logging.level.com.myapp.packagename=INFO
logging.level.org.springframework=ERROR
INFO means it will print logging of classes in your package and all sub package at INFO/ERROR/WARN level, while for spring related classes only print if there are ERROR level logging.
You can configure logging properties as follows:
logging.level.* = ERROR
logging.level.package_name=DEBUG
Example:
logging.level.com.example.controller=DEBUG
So classes under com.example.controller package will be logged, others only on error will be logged.
I hope this helped!!

how can i get a detailled log to Spring Beans loading?

i need a detailed log to see how spring loads my interfaces and their respective implementation classes .
i want to monitor Spring's BeanFactory's behaviour and have a look at how it manages the dependencies injections .
Add a log4j.xml to your project and the appropriate JAR files. Log to the console at INFO or DEBUG and you'll have what you want.

Resources