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

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

Related

Can someone explain the flow of execution of spring boot application?

I am working on a spring boot application.
I wanted to know what happens when the application started running and before it becomes ready for user interaction.
I tried going through the console logs but I am still unsure as to what happens when.
I believe you should elaborate a bit more your question. That's because you can build different types of applications using Spring Boot. In a nutshell, during the start up the application will basically try to load the "beans" defined in the related context(s), pre-configured components, define the active profile, properties files, etc. Also some Spring and application events are generated during the start up.
A good way to understand what's going on behind the scenes is running the application in DEBUG mode. By default, the log level of the application is set as INFO.
Have a look at this link for further details:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-application
I hope this can help you as start point.

Spring Boot Audit Logging by Example

Almost every aspect of Spring Boot's documentation have proven to be treasure troves of copious amounts of information. That is until I get to Chapter 50: Auditing.
I am trying to understand the 2 paragraphs that make up this entire chapter. If I'm reading it correctly, then when I run my Spring Boot app in "production mode" (that is, as a built/packaged uberjar via java -jar path/to/myapp.jar) then every time an access event (auth attempt/success/fail) occurs, that event will get logged/recorded somewhere.
I haven't done any config whatsoever. I run my app in "prod mode" and log in. I expect to see some console/log output indicating the auth event, but I don't see any. I log out, same deal (no console output). I try to log in with a bad username, and again, nothing in the console output.
Is Spring Boot recording access events somewhere else, besides console/log output? If so, where and why?
Do I need to define any #Beans and register them with some kind of event listener? If so, can someone please provide a succinct code example?
Basically I'm just looking to get Spring Boot's default audit logging pumping events to STDOUT (console). Any ideas?

Spring Boot application log level

I want to change the log level of a Spring Boot application that is running.
Is it possible to change the log level at runtime? Right now I have the logger configuration in my jar itself.
Changing the log level while the application is running is part of the underlying logger implementation.
You did not specify the logger implementation you are using so I will assume you are using the default logback provided via the spring-boot-starter-logging or spring-boot-starter-web dependencies.
Comment out any logger related configurations from application.properties
e.g.
#logging.path=logs
#logging.level.org.springframework.web= INFO
#logging.level.=INFO
Add logback.xml in the root of your classpath with tag
See http://logback.qos.ch/manual/jmxConfig.html
Start the application and open JConsole and go to MBeans tab.
Select the package ch.qos.logback.classic.JMxConfigurator.Under default locate the setLoggerLevel operation
e.g. org.springframework.web, DEBUG
The change will be effective immediately.
For other logger libraries see the spring boot user guide
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
And library specific information e.g. for log4j
http://www.sureshpw.com/2012/04/dynamic-logging-with-log4j.html
A different approach is to repeat the about steps without JMX and use configuration watcher
Logback Automatically reloading configuration file upon modification
Log4j configureAndWatch(java.lang.String, long)
If you want to change the logging level of an already running Spring Boot application you can take a look at spring-cloud-config. Refer to:
http://cloud.spring.io/spring-cloud-config/:
Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments.
You can centrally manage the properties in config server and in your current application - applications.properties file (check bootstrap.properties) create an entry for
spring.application.name=application name
Using #RefreshScope annotation in your client application you will be able to refresh your application runtime and see the updated logging level property.
With the release of Spring Boot 1.5, if you have actuator in your Boot application you can do this through an out of the box REST API.
1.5 actuator provides an endpoint called 'loggers' which you can GET to view the configuration, and POST to make runtime changes.
Ex.
curl -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "DEBUG"}' http://localhost:8080/loggers/org.springframwork

Spring YARN: How to create a Tracking UI and correctly wire a proxy to it?

I want to deploy an application with a web interface. I want to use Spring YARN for this because that eases all the basic setup, and I can start the application with java -jar.
What steps do I have to do to:
have my application expose a web interface
have the tracking URI I get when submitting it proxy to that web interface
Unfortunately, I cannot find anything about this on the net, there is npthing on that particular issue in the Spring documentation and Google searches do not get me the correct results either.
Easiest way to do this is simply use Spring YARN Boot application model and framework is then trying to do the heavy lifting on your behalf. I actually showed a demo of this during my session at SpringOne 2GX 2014. You can find my session recording from youtube https://www.youtube.com/watch?v=qlvX7_r9aUA.
Interesting stuff for this particular feature is at the end (starting from 1:16:22) and you can see how web server address is registered into YARN resource manager and how I query it using a Spring YARN Boot CLI (around 1:32:13). Spring YARN will actually see that there is an embedded servlet context and registers it automatically. In this demo property "server.port=0" makes tomcat to choose random port which is then registered.
Code for this particular UI demo can be found from github https://github.com/SpringOne2GX-2014/JanneValkealahti-SpringYarn/tree/master/gs-yarn-rabbit. Demo was around RabbitMQ just to have some real UI functionality and not just a dummy hello world page.
There's also more up-to-date sample in https://github.com/spring-projects/spring-hadoop-samples/tree/master/boot/yarn-store-groups which doesn't have a real UI(just Boot management endpoints). Thought it's relatively easy to add Spring MVC magic there just by following normal Boot functionality(i.e. following https://spring.io/guides/gs/rest-service).
Lemmy know if this helps!

Externalizing logging in Spring Boot apps

I'm trying to externalize logging configuration. However, any configuration I establish (e.g. -Dlogback.configurationFile=...) is wiped out the moment I call SpringApplication.run(). Is there a way to prevent this?
Try 'logging.config' (or use one of the the conventional locations, e.g. 'classpath:/logback.xml'). Docs here: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-custom-log-configuration.

Resources