Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk NodeJS and logs

I want to migrate my NodeJS project from single EC2 to ElasticBeanstalk. In my current code I use the dependency log4js which create a log file on the filesystem. On EC2 this works create but what is the best way in ElasticBeanstalk to log something? If I download the generated logs from ElasticBeanstalk my custom log file from log4js isn't present.

Best regards

like image 503
user1791139 Avatar asked Nov 17 '14 12:11

user1791139


People also ask

How do I check logs in AWS Elastic Beanstalk?

Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list. In the navigation pane, choose Logs.

Where does Elastic Beanstalk store logs files?

Within the Elastic Beanstalk configuration, you can specify a retention period (e.g. 30 days) before they're deleted. The logs are searchable directly within the AWS Console (within the CloudWatch section).

Does Elastic Beanstalk support node JS?

Elastic Beanstalk provides platforms for programming languages (Go, Java, Node. js, PHP, Python, Ruby), application servers (Tomcat, Passenger, Puma), and Docker containers.


1 Answers

In order to see the logs you can:

  • Press on your elastic beanstalk environment
  • Press 'Logs' (on the left side)
  • Press 'Request Logs' (usually just last 100 lines should be fine) and download the file.

You can see a few different log files there.

I believe that logs you write using log4js in Node.js will be under:

/var/log/nodejs/nodejs.log

I like to ssh into the elastic beanstalk instance and tail the log to see it updating "live" (when I use my server). to do it run the following:

eb ssh

tail -n 50 -f /var/log/nodejs/nodejs.log

The above log path depends on the type of the EC2. on Linux 2 it is: /var/log/web.stdout.log

In general, when you deploy to Elastic Beanstalk linux environment your app will be under:

/var/app/current

Try finding your log files under this path- they will have the same name as when you run the app locally.

like image 92
Rayee Roded Avatar answered Oct 08 '22 10:10

Rayee Roded