使用Elastic Beanstalk登录 [英] Logback with Elastic Beanstalk

查看:102
本文介绍了使用Elastic Beanstalk登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Elastic Beanstalk记录应用程序日志时遇到麻烦.我在"Tomcat 8.5上,在64位Amazon Linux 2/4.1.3上运行Corretto 11的环境"上,在AWS Elastic Beanstalk上运行spring mvc(NOT springboot)WAR文件.

I am having trouble with logging application logs with Elastic Beanstalk. I am running an spring mvc (NOT springboot) WAR file on AWS Elastic Beanstalk on a 'Tomcat 8.5 with Corretto 11 running on 64bit Amazon Linux 2/4.1.3' environment.

以前,我认为问题是我无法检索由应用程序编写的日志.但是,在遵循了此问题的建议之后(使用Logback进行AWS Elastic Beanstalk应用程序日志记录)我能够确定查看日志没有问题-实际的问题是甚至没有写入日志.我ssh到该实例,并且未在/var/log目录中创建日志文件

Previously I thought the problem was that I was unable to retrieve logs that were written by the application. However, after following suggestion in this question (AWS Elastic Beanstalk Application Logging with Logback) I was able to determine that there was no issue viewing the logs - the actual problem is that the logs are not even written. I ssh to the instance and the log file was not created in the /var/log directory

作为参考,这是我的logback文件追加器(链接的问题中的完整logback.xml):

For reference, here is my logback file appender (full logback.xml in the linked question):

<appender name="APPLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/var/log/java.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>/var/log/java_%d{yyyy-MM-dd}_%i.log</FileNamePattern>
            <!-- keep 14 days' worth of history -->
            <maxHistory>14</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the File size reaches 10MB -->
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread][%X{remoteHost}] %-5level %c{1} - %msg%n</pattern>
            <!-- <pattern>%d %-5p %c{1} - %m%n</pattern> -->
        </encoder>
    </appender>

该应用使用的是slf4j-api-1.7.6,logback-classic-1.2.3和logback-core-1.2.3.在本地在Tomcat服务器上加载相同的war时,应用程序日志将按预期工作.

The app is using slf4j-api-1.7.6, logback-classic-1.2.3 and logback-core-1.2.3. The application logs works as expected when loading the same war on Tomcat server locally.

因此,我现在很想知道(1)Logback是否可与Elastic Beanstalk一起使用?(2)如果是,将日志写到/var/logs 目录是否需要特殊的操作(权限?,其他依赖项)?

So now I am wondering (1) Does logback work with Elastic Beanstalk? (2) If yes, does it require something special (permissions?, other dependencies) to write logs to the /var/logs directory?

推荐答案

基于评论.

此问题是由权限引起的.默认情况下,EB上的用户应用程序无权访问/var/logs .

The issue was caused by permissions. By default user applications on EB do not have access to /var/logs.

解决方案是修改权限,以便可以将日志放置在/var/log/tomcat 中.

The solution was to modify the permissions so that the logs can be placed in /var/log/tomcat.

这篇关于使用Elastic Beanstalk登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆