I have a java Spring Boot application deployed to an Azure App Service environment. I am using log4J2 to handle my logging for the application and writing the logs to the same location as the other log files created for the app service. I am able to find the log file (spring.log) my spring boot application is creating and logging to in the KUDU editor, but I cannot figure out where to go from there. My goal is to make the lines that the java application is writing to the log file available from Azure portal so I can, for example, setup alerts when my application writes "Some specific exception". However, I cannot find a way to see anything from this log file from the "logs" option of the app service from azure portal. I can see some log entries saying that this log file was created/updated/deleted, but the actual contents of the log file are what I am after. Does anyone know how to do this or if it is even possible? For additional context my application is deployed as a jsp app on a tomcat server deployed to the app service as a war file along with the following web.config file
<?xml version="1.0" encoding="UTF-8"?> `
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed"/>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%JAVA_HOME%binjava.exe" arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%sitewwwrootmy-application=name.war"">
</httpPlatform>
</system.webServer>
</configuration>
I have yet to even be able to find the console output from the deployed version, but of course I can see the console output when I run it from my IDE locally.
I’ve turned on ‘diagnostic settings’ for the application and am sending all available options to a log analytics workspace, but querying this workspace still does not give me any results related to the actual contents contained within the file.
2
Answers
I created a sample Spring Boot application to generate logs in
spring.log
locally. I successfully found the logs in the Azure Web App KUDU under File Manager > LogFiles > Application >spring.xxxxx.log
.LoggingController.java :
application.properties :
log4j2.xml :
web.config :
pom.xml :
I got the below output in the browser.
I got the below logs in the
spring.log
file.Azure Web Apps :
We can view the
spring.log
data in the Azure Web App using KUDU by navigating to File Manager > LogFiles > Application >spring.xxxxx.log
.Logs :
You can integrate Azure Application Insights to your Spring Boot application: https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-spring-boot?source=recommendations
All you need is a dependency, a line in main method of your application to initiate the agent and the configuration properties that point to your Application Insights.
With that done, the Application Insights agent will auto-collect logs from Log4j2 and send them to Azure Application Insights. From there you can set up alerts and have better control on your logs.