Node.js OpsWorks Layer Console Logs

I have an Opsworks stack with Node.js Layer and Node.js Application. I am wondering if anyone knows where console logs from my application are printed on an ubuntu 14.04LTS instance. I know that opsworks uses monit to run my application, but I'm not sure where its log output is.

Thanks!

+6
source share
4 answers

It is so annoying that the Monit configuration displayed for Node.JS applications on Opsworks does not send the result anywhere! Source for this application . (It surprised me when I found out about it!)

What I recommend you do is override this template - see the OpsWorks documentation on overriding templates : essentially all you have to do is copy the Monit configuration paste from Amazon, but change line 2 to redirect the output to a file, as shown below:

start program = "/bin/bash -c 'cd <%= @deploy[:deploy_to] %>/current ; source <%= @deploy[:deploy_to] %>/shared/app.env ; /usr/bin/env PATH=$PATH:/usr/local/bin PORT=<%= @deploy[:nodejs][:port] %> NODE_PATH=<%= @deploy[:deploy_to] %>/current/node_modules:<%= @deploy[:deploy_to] %>/current /usr/local/bin/node <%= @monitored_script %> &> <%= @deploy[:deploy_to] %>/current/log/production.log'"

+7
source

I found the logs by doing the following (similar to @RyanWilcox's comment):

  • I found my "current" deployment in / srv / www / {APP NAME} / current /
  • listing files, I could see a symbolic link to the log directory (the log should be symlinked to something like / srv / www / {APP NAME} / shared / log
  • I ran into a permission problem trying to connect to this directory, so I switched to superuser without password using the command “sudo su” and then I could access the directory
  • finally, in the logs directory, I could see the nodejs console logs for STDERR and STDOUT

... and father Bob is your father's father.

+1
source

You can find it in the application directory, then you will find this shared / log path

for example: /srv/www/my_app/shared/log

+1
source

If the behavior of console.log has not been changed, node outputs console.log logs to standard application output ( stdout ). If you are running the node application in the console or using ssh, you should see the logs there. Otherwise, try redirecting the stdout of your application to a file so that you can see it even if you started it without a console, as follows: node myapp.js > logfile

The preferred way would be a Forever user to make sure the application is always on, and there you can redirect your output (both stdout and stderr) as follows:

 />forever -o forever.out -e forever.err myapp.js 
-2
source

Source: https://habr.com/ru/post/981636/


All Articles