简体   繁体   中英

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. I thought I could simply log to a file on Beanstalk.

In my application.properties file I set

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.

With Beanstalk I tried /var/log, var/log/tomcat, /home/webapp/, ./, ~, and various other values. Nothing worked.

I even tried what was suggested here with no luck: 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. Thus you can't write to it.

The proper way of adding your log files to be recognized by EB is through config files.

Specifically, assuming Amazon Linux 2, you can create .ebextensions/mylogfiles.config with the content of:

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/current is the home folder of your app.

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