简体   繁体   English

Spring 在 AWS Elastic Beanstalk 上启动并记录到文件

[英]Spring Boot on AWS Elastic Beanstalk and logging to a file

I have been looking to find an easy way to view debug statements on Beanstalk as I develop.在开发过程中,我一直在寻找一种简单的方法来查看 Beanstalk 上的调试语句。 I thought I could simply log to a file on Beanstalk.我以为我可以简单地登录到 Beanstalk 上的文件。

In my application.properties file I set在我的 application.properties 文件中我设置

logging.file.path=/var/log

And that did not produce any results even on my local machine.即使在我的本地机器上也没有产生任何结果。 I am not sure if it's a permission issue or what, but locally I set the path to my home directory and then I saw the file, spring.log, appear.我不确定这是权限问题还是什么,但我在本地设置了主目录的路径,然后我看到文件 spring.log 出现了。

With Beanstalk I tried /var/log, var/log/tomcat, /home/webapp/, ./, ~, and various other values.对于 Beanstalk,我尝试了 /var/log、var/log/tomcat、/home/webapp/、./、~ 和其他各种值。 Nothing worked.没有任何效果。

I even tried what was suggested here with no luck: https://medium.com/vividcode/logging-practice-for-elastic-beanstalk-java-apps-308ed7c4d63f我什至尝试了这里的建议但没有运气: https://medium.com/vividcode/logging-practice-for-elastic-beanstalk-java-apps-308ed7c4d63f

If logging to file is not a good idea, what are the alternatives?如果记录到文件不是一个好主意,还有什么替代方法? I have Googled a lot about this issue and all answers are not very clear.我在谷歌上搜索了很多关于这个问题的答案,所有答案都不是很清楚。

Yes, this is permission issues.是的,这是权限问题。 Your app runs under webapp user, while /var/log is own by root.您的应用程序在webapp用户下运行,而/var/log由 root 拥有。 Thus you can't write to it.因此你不能写信给它。

The proper way of adding your log files to be recognized by EB is through config files.添加日志文件以被 EB 识别的正确方法是通过配置文件。

Specifically, assuming Amazon Linux 2, you can create .ebextensions/mylogfiles.config with the content of:具体来说,假设 Amazon Linux 2,您可以使用以下内容创建.ebextensions/mylogfiles.config

files: 
  "/opt/elasticbeanstalk/config/private/logtasks/bundle/myapplogs.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
       /var/app/current/log/*.log

Obviously, /var/app/current/log/*.log would point to location where your app stores its log files.显然,/var/app/ /var/app/current/log/*.log log/*.log 将指向您的应用程序存储其日志文件的位置。 /var/app/current is the home folder of your app. /var/app/current是您的应用程序的主文件夹。

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

相关问题 带有弹簧启动应用程序的aws弹性beanstalk - aws elastic beanstalk with spring boot app 在AWS Elastic BeanStalk上运行的Spring Boot应用程序中配置AWS RDS - Configuring AWS RDS in a Spring Boot Application running on AWS Elastic BeanStalk 使用 AWS Elastic Beanstalk 在 AWS 上部署 Spring Boot 应用程序 - Deploying a Spring Boot Application on AWS Using AWS Elastic Beanstalk 使用 AWS Elastic Beanstalk 进行应用程序日志记录 - Application logging with AWS Elastic Beanstalk 使用 Elastic Beanstalk (AWS) 进行 Django 日志记录 - Django Logging with Elastic Beanstalk (AWS) 为什么Spring Boot War文件只能在本地主机上使用工件ID而不在AWS Elastic BeanStalk中工作? - Why does Spring boot war file works in localhost only with artifactId but not in AWS Elastic BeanStalk? AWS CodePipeline 将 Spring Boot 应用程序部署到 Elastic BeansTalk - AWS CodePipeline deploy Spring Boot application to Elastic BeansTalk 带有SSL / HTTPS的Spring Boot项目无法在AWS Elastic Beanstalk上运行 - Spring Boot project with SSL / HTTPS not working on AWS Elastic Beanstalk aws 弹性 beantalk 上的 HTTP 到 HTTPS 不适用于 Spring Boot - HTTP to HTTPS on aws elastic beanstalk not working for Spring Boot Spring Boot Application无法在AWS Elastic Beanstalk中进行一次身份验证 - Spring Boot Application not authenticating once in AWS Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM