[英]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.