6

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

Thanks!

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
mu888
  • 65
  • 3

4 Answers4

7

So annoyingly enough, the Monit configuration rendered for Node.JS apps on Opsworks doesn't send the output anywhere! Source for this claim. (This surprised me when I learned about it!)

What I recommend doing is overriding that template - see the OpsWorks documentation on overriding templates: essentially all you need to do is copy paste the Monit config from Amazon, but change line 2 to redirect the output to a file, like I do below so:

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'"

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60
  • thanks! yeah, thats weird that they don't send the output anywhere. – mu888 Feb 02 '15 at 21:26
  • Thanks RyanWilcox! I've added a similar override to [aws-cookbook-boilerplate](https://github.com/dmarcelino/aws-cookbook-boilerplate/blob/master/opsworks_nodejs/templates/default/node_web_app.monitrc.erb#L2). – Dário May 15 '15 at 00:22
  • Thanks for this - but how do you access the log and where to look for it when you SSH to the instance? Thanks! – Leo Jun 21 '15 at 00:55
  • 2
    @Leo the logs will be saved at /srv/www/YOUR APP NAME/current/log/production . (Or what I do, hook that file up to be monitored by AWS CloudWatch Log - or a similar service - so you can use a web UI. – RyanWilcox Jun 21 '15 at 12:09
  • Thanks a lot, @RyanWilcox – Leo Jun 21 '15 at 21:47
2

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

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

Mukul Kant
  • 7,074
  • 5
  • 38
  • 53
Ahmed Shendy
  • 389
  • 2
  • 5
1

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

  1. I found my "current" deployment in /srv/www/{APP NAME}/current/
  2. listing files, I could see the log directory symlink (log should be symlinked to something like /srv/www/{APP NAME}/shared/log
  3. I ran into a permissions issue trying to cd to this directory, so I switched to the super user without a password using the command "sudo su" and then I could access the directory
  4. finally in the logs directory, I could see the nodejs console logs for STDERR and STDOUT

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

Rob
  • 5,534
  • 1
  • 22
  • 22
-2

Unless behavior of console.log was altered, node will output console.log logs to the application's standard output (stdout). If you are running your node application in a console or using ssh, you should see the logs there. Otherwise, try redirecting the stdout of your application to a file so you can see it even if you run it without a console, in this way: node myapp.js > logfile

A preferred way would be to user Forever to make sure you application is constantly on and there you can redirect your output (both stdout and stderr) as follows:

/>forever -o forever.out -e forever.err myapp.js
Ozk
  • 181
  • 11