简体   繁体   English

Spring Boot + Azure - 应用程序在 Azure 上启动后停止记录

[英]Spring Boot + Azure - App stops logging after starting up on Azure

I'm working on this Spring Boot app using logback and apache commons logging, configured to generate log files within a 'logs' folder.我正在使用 logback 和 apache 公共日志记录开发这个 Spring Boot 应用程序,配置为在“日志”文件夹中生成日志文件。 The app works perfectly well on local, however when it's deployed to Azure, the app logs will only go up until the moment the application starts, and after Spring Boot prints the "Started XYZApplication in 36.186 seconds", nothing else shows up.该应用程序在本地运行良好,但是当它部署到 Azure 时,应用程序日志将只有 go 直到应用程序启动,并且在 Spring 引导打印“在 36.186 秒内启动 XYZApplication”之后,没有其他显示。

We tried to add different levels of logs, including INFO and ERROR, and it still doesn't show up in the log file.我们尝试添加不同级别的日志,包括INFO和ERROR,但它仍然没有显示在日志文件中。 Next up we've created an endpoint to returned some info in the response:接下来我们创建了一个端点以在响应中返回一些信息:


// Log and LogFactory from org.apache.commons.logging
private static final Log LOG = LogFactory.getLog(CacheAdminController.class);


@RequestMapping(value = "/checkLogs", method = GET)
public ResponseEntity<String> checkLogs() {
    LOG.info("This INFO log should show up");
    LOG.error("This ERROR log should show up");
    String response = String.format("Is log error enabled? %s Is log info enabled? %s Is log debug enabled? %s", LOG.isErrorEnabled(), LOG.isInfoEnabled(), LOG.isDebugEnabled())
    return ResponseEntity.ok(response);
}

This endpoint returns true for both the isInfoEnabled and isErrorEnabled, but the actual LOG.info and LOG.error won't show up in Azure. It's a really baffling situation.对于 isInfoEnabled 和 isErrorEnabled,此端点都返回 true,但实际的 LOG.info 和 LOG.error 不会显示在 Azure 中。这真是令人费解的情况。 What could be causing this?是什么原因造成的? Why is it enabled but not coming up?为什么它启用但不出现? And why is it only happening when deployed to Azure?为什么它只在部署到 Azure 时发生? The logback configuration is the exact same for both local and Azure, so I don't think that's it.本地和 Azure 的 logback 配置完全相同,所以我认为不是这样。

I've even set my log levels to TRACE but couldn't find any useful information in there.我什至将我的日志级别设置为 TRACE,但在那里找不到任何有用的信息。

If anyone could shed a light, that would be greatly appreciated.如果有人能阐明这一点,那将不胜感激。

I've even set my log levels to TRACE but couldn't find any useful information in there.我什至将我的日志级别设置为 TRACE,但在那里找不到任何有用的信息。

I have tried using TRACE logs in my Application.Properties我尝试在我的Application.Properties中使用TRACE日志

在此处输入图像描述

Then, I created a Logback.xml File.然后,我创建了一个Logback.xml文件。 see below!见下文!

<configuration>  
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>  
<property name="LOG_FILE" value="logs/app.log"/>  

<appender name="FILE-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">  
<file>${LOG_FILE}</file>  

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">  
<fileNamePattern>logs/archived/app.%d{yyyy-MM-dd}.%i.log</fileNamePattern>  
<!-- each archived file, size max 5KB -->  
<maxFileSize>5KB</maxFileSize>  
<!-- total size of all archive files, if total size > 20KB,  
it will delete old archived file -->  <totalSizeCap>20KB</totalSizeCap>  
<!-- 60 days to keep -->  
<maxHistory>60</maxHistory>  
</rollingPolicy>  
<encoder> <pattern>%d %p %c{1.} [%t] %m%n</pattern>  
</encoder> </appender>  
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">  
<layout class="ch.qos.logback.classic.PatternLayout">  
<Pattern>  %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n  
</Pattern>  
</layout> </appender>  

<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">  
<smtpHost>smtp.gmail.com</smtpHost>  
<smtpPort>587</smtpPort>  
<STARTTLS>true</STARTTLS>  
<username>emailid</username>  
<password>password</password>  
<to>emailid</to>  
<from>emailid</from>  
<subject>TESTING: %logger{20} - %m</subject>  

<layout class="ch.qos.logback.classic.html.HTMLLayout"/>  
</appender>  
<logger name="com.Springbootfirst" level="error" additivity="false">  
<appender-ref ref="EMAIL"/>  
</logger>  
<logger name="com.Springbootfirst" level="trace" additivity="false">  
<appender-ref ref="FILE-ROLLING"/>  
</logger>  
<root level="error">  
<appender-ref ref="FILE-ROLLING"/>  
</root>  
<logger name="com.Springbootfirst" level="debug" additivity="false">  
<appender-ref ref="CONSOLE"/>  
</logger> <root level="error">  
<appender-ref ref="CONSOLE"/>  
</root>  
</configuration>

I Started running My application in local, its working fine and started creating logs and then, Deployed in Azure Spring App我开始在本地运行我的应用程序,它工作正常并开始创建日志,然后部署在 Azure Spring App 在此处输入图像描述在此处输入图像描述

App is Running fine in Azure also.应用程序在 Azure 中也运行良好。 在此处输入图像描述

在此处输入图像描述

And Then, Logs also Generated.然后,日志也生成了。 Check below!检查下面!在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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