Change Spring Webclient log level from DEBUG to WARN or ERROR - java

I have a very simple java application (not spring boot application), in which I am using Spring WebClient to parallely make HTTP calls. I have initialised it in global as below :
private static final WebClient webClient = WebClient.create();
and using it across my application. Now the issue is that when it starts, it prints a message as following :
21:10:59.417 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
After that it starts to print all(a ton of) debug logs, which hamper my capability to test and application
Is there any way to change the log level if WebClient is used as above, and not in SpringApplication ? I have tried all solutions offered in Disable Spring Boot Webclient logs, and nothing works.

You can set the level in application.properties like
logging.level.root= INFO

Related

Implement tracing in a spring boot application

I have a spring boot application and I want to configure log tracing to all the application, I added the setup for **datadog Agent ** as in in the documentation: https://docs.datadoghq.com/tracing/setup_overview/setup/java/?tabs=containers and I can see trace ids and spanIds associated with each request, there are other options such as Spring cloud Sleuth to add tracing and span ids as well:
https://spring.io/projects/spring-cloud-sleuth
and also in the datadog documentation, there is a way for connecting Java logs and tracing in https://docs.datadoghq.com/tracing/connect_logs_and_traces/java/?tabs=log4j2
I have a confusion with this three approaches and which one of them I can use for the tracing purpose, with spring sleuth I know that is easier to generate span a trace ids, but not sure if them are sent to datadog or I need to configure something additional.
Also the connecting Java logs and tracing vs datadog agent its not clear for me.
I am new with this topic and it is not clear for me how can I implement tracing for all the process included in a request.

Spring Integration: save integration flows logs to database

I have been required to log the integration flow requests and save to logs that I am getting to the database. Logging the request is working fine, but my question is how can I store this logs that I am getting from the logAndReply() to the database?
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST))
.validator(new Validator()).errorChannel("errorHandler.input"))
.transform(Transformers.objectToString())
.transform(new TransformingMethod())
.logAndReply(LoggingHandler.Level.INFO);
This is the part of your logging framework and in most cases it is called JdbcAppender. For example Log4J:
https://howtodoinjava.com/log4j2/jdbcappender-example/
log4j2 JDBCAppender with Spring
http://smasue.github.io/log4j2-spring-database-appender
On the other hand, instead of relying on the logging framework, you can do it yourself and use a JdbcMessageHandler: https://docs.spring.io/spring-integration/docs/current/reference/html/jdbc.html#jdbc-outbound-channel-adapter

How to configure Spring Cloud logging?

I have a Spring Boot application with Spring Cloud components, namely org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config.
The component produces logs at WARN level when the application starts which I want to suppress.
Setting a log level in the application.yml like
logging:
level:
org.springframework.cloud.aws.paramstore.AwsParamStorePropertySourceLocator: ERROR
did not work. Apparently its because this cloud component works at bootstrap time before the Spring Boot context starts and the application.yml is read.
How can I suppress this component logs in the best way?

Spring Webflux - logging connection ID and new Connection log not displayed when using Webflux webclient

Many tutorials online are pointing out the importance of having connection ID in a Spring Webflux application.
For instance, see this screenshot taken from a presentation in a conference.
However, I am not getting those IDs. I can only see the part with the time, up until the [ctor-http-nio5].
I cannot see the connection ID, I cannot see the statement "New http connection"
What can be the root cause of me not being able to display such? I really would like to see those interesting logs.
Thank you for your help
This ID is unique for each of the connections made to your server and you can extract it by calling the getLogPrefix() method of ServerWebExchange class and can append it to your logs by directly or by putting it to the MDC.
By default spring framework logs this id in the framework logs.
These framework logs are at the DEBUG level so you need to enable debug level to see the logs with ids.
By adding the following configuration to the application.properties you can see the logs with ids.
logging.level.org.springframework=DEBUG

checking whether spring boot application is running or not

I've created a spring boot project and deployed it on a vm. I've added a command in local.rc that starts the spring boot application on reboot. I want to check whether the command got executed and the application is running. How do I do that?
There are two ways
On system level - you can run your project as a service, which is documented in the Official documentation - Deployments. Then you can query the application status service myapp status.
On application level - include Spring Boot Actuator in your app and use the Actuator endpoints such as /actuator/health as per Official documentation - Production Ready Endpoints. These endpoints can be exposed via HTTP or JMX.
Note: prior to spring boot 2.0 the actuator endpoint is /health
If it's a web project, it makes sense to include spring-boot-actuator (just add a dependency in maven and start the microservice).
In this case, it will automatically expose the following endpoint (for example, its actually can be flexibly set up):
http://<HOST>:<PORT>/health
Just issue an HTTP GET request, and if you get 200 - it's up and running.
If using an actuator is not an option (although it should be really addressed as a first bet), then you can merely telnet to http://<HOST>:<PORT>
The ratio behind this is that that PORT is exposed and ready to "listen" to external connections only after the application context is really started.

Categories

Resources