Search code examples
javaspring-bootlogbackazure-application-insights

Conditional verbose error logging to Azure application-insights from a Java Spring boot application


I have a spring boot application with a pretty standard logback configuration. I know I can turn on/off the verbose logging by changing the logging level property to only log errors (<root level = "ERROR">). And I have configured my app to only log errors in the application-insights azure resource that I have, so as to avoid verbose logging till it's necessary. All of this is working fine.

However, as soon as I get an error, I want to start verbose logging for a certain period of time let's say 2hrs, so as to help with the troubleshooting. And this is what I am unable to achieve. I am pretty new to Java as well as Azure resource configurations, so any idea will be really helpful.


Solution

  • Appreciate the answer and comment on the question, they will prove to be a good resource for whoever comes across this question in future. However, a more pointed answer to this situation is needed. I was able to achieve the conditional, time based, verbose logging for my application by the following approach:

    1. Create an alert in azure portal pointing to the azure resource in use.
    2. Configure that alert's action group to call a controller action method, selecting webhook as the action type.
    3. Inside your controller action method, change the logging level setting to verbose logging for desired period of time, and reset it back to non-verbose after that. (I used non blocking Thread.sleep() for this)
    4. Enjoy the automation :)