AWS Elastic Beanstalk NodeJS和日志

时间:2022-08-25 08:40:37

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.

我想将我的NodeJS项目从单个EC2迁移到ElasticBeanstalk。在我当前的代码中,我使用依赖log4js,它在文件系统上创建一个日志文件。在EC2上,这可以创建但是ElasticBeanstalk中记录内容的最佳方法是什么?如果我从ElasticBeanstalk下载生成的日志,则log4js中的自定义日志文件不存在。

Best regards

最好的祝福

1 个解决方案

#1


4  

In order to see the logs you can:

要查看日志,您可以:

  • Press on your elastic beanstalk environment
  • 按下弹性beanstalk环境
  • Press 'Logs' (on the left side)
  • 按“日志”(在左侧)
  • Press 'Request Logs' (usually just last 100 lines should be fine) and download the file.
  • 按“请求日志”(通常只有最后100行应该没问题)并下载文件。

You can see a few different log files there.

您可以在那里看到一些不同的日志文件。

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

我相信你在Node.js中用log4js写的日志将在:

/var/log/nodejs/nodejs.log

/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:

我喜欢ssh进入弹性beanstalk实例并拖尾日志,看它更新“live”(当我使用我的服务器时)。要做到这一点运行以下:

eb ssh

eb ssh

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

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

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

通常,当您部署到Elastic Beanstalk linux环境时,您的应用程序将位于:

/var/app/current

在/ var /应用/电流

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

尝试在此路径下查找日志文件 - 它们与您在本地运行应用程序时的名称相同。

#1


4  

In order to see the logs you can:

要查看日志,您可以:

  • Press on your elastic beanstalk environment
  • 按下弹性beanstalk环境
  • Press 'Logs' (on the left side)
  • 按“日志”(在左侧)
  • Press 'Request Logs' (usually just last 100 lines should be fine) and download the file.
  • 按“请求日志”(通常只有最后100行应该没问题)并下载文件。

You can see a few different log files there.

您可以在那里看到一些不同的日志文件。

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

我相信你在Node.js中用log4js写的日志将在:

/var/log/nodejs/nodejs.log

/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:

我喜欢ssh进入弹性beanstalk实例并拖尾日志,看它更新“live”(当我使用我的服务器时)。要做到这一点运行以下:

eb ssh

eb ssh

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

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

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

通常,当您部署到Elastic Beanstalk linux环境时,您的应用程序将位于:

/var/app/current

在/ var /应用/电流

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

尝试在此路径下查找日志文件 - 它们与您在本地运行应用程序时的名称相同。