简体   繁体   中英

How to have access to Azure's Tomcat logs for Java App Service deployment

I'm using for the first time Azure to deploy Java Spring Boot applications as a App Service that I used to host on a local Tomcat.

I managed to deploy from Github to Azure directly but I cannot find any logs about the application on platform. On a Tomcat server all the logs are usefull and in my application I'm using Log4j to log into files into Tomcat/logs folder.

Here is my General Settings in the Configuration tab: 在此处输入图像描述

I'm getting lost with all the post that I've found online that I find unclear and also, as I'm just trying Azure right now with the trial offer I might not have access to all functionnality.

Thank you for any help for this !

Log4j might not work that wonders like Application Insights can do in Azure cloud. I would recommend you to go through this great blog post, that explain step-by-step about migrating your Boot Application to Azure App service and how well you can integrate Monitoring and Logging: Migrating Spring Java Applications to Azure App Service (Part 2 — Logging and Monitoring)

Their example Spring application uses the Log4j logging framework to log required data and traces. It's common practice to forward logs to a central logging system (like ELK, Splunk, etc.). Azure Application Insights provides the ability to forward logs to Azure's central logging system, Log Analytics, with configurable retention periods and the ability to further filter and direct logs to other systems. A common example is to forward logs that are important for security review to SIEM systems.

First, add AppInsights logging library as shown below:

<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-api</artifactId>
 <version>2.11.1</version>
</dependency>
<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-core</artifactId>
 <version>2.11.1</version>
</dependency>
<dependency>
 <groupId>com.microsoft.azure</groupId>  <artifactId>applicationinsights-logging-log4j2</artifactId>
<version>[2.1,)</version>
</dependency>

Define AppInsights Appender that will forward logs to Azure Log Analytics:

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\home\\LogFiles\\logs.txt
log4j.appender.aiAppender=com.microsoft.applicationinsights.log4j.v2.ApplicationInsightsAppender
log4j.logger.tutorial=DEBUG, file, aiAppender
log4j.logger.com.microsoft=DEBUG, file, aiAppender

As a result you could see all log statements in a Search view for the Log Analytics:

在此处输入图像描述

If you still want to use Log4j , check out Log with the Azure SDK for Java and Log4j .

I finally managed to properly deploy a Web App first using the maven azure plugin and it works perfectly. I also saw the equivalent of the Tomcat's stdout file but as a stream so not very conclusive.

I wanted to enable diagnostic logging but in the free subscription it seeems there is no way to do that.

在此处输入图像描述

Is there a way to try it out? Thanks !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM