Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loggly not working via Winston on Pi

I have an IoT project running on a Raspberry Pi 2 using the Raspbian Jessie OS.

It's a web server running in NodeJS (v4) and I'm using Winston to log to Loggly's logging service. All works well when the project is kicked off via npm start from terminal (when running as 'pi' or via sudo -s). However, when the project starts on boot, the logging doesn't work and I can't work out why.

To start the project on boot I created a etc/init.d script. The project starts and serves traffic, everything works great except for logging. I can't see any errors (though not having logging doesn't help). This is how I start my project from inside my etc/init.d script:

/usr/bin/node /var/www/curtains/server.js

I'm using winston: https://www.npmjs.com/package/winston and winston-loggly: https://www.npmjs.com/package/winston-loggly.

Any ideas why, when the process is started on bootup the logging doesn't work?

Adding winston initialization code as requested:

var winston = require('winston');
require('winston-loggly');

 winston.add(winston.transports.Loggly, {
    token: "<snip>",
    subdomain: "<snip>",
    tags: ["tag", ip.address()],
    json:true
});

winston.log('info',"Server.js starting up");
like image 496
ConfusedNoob Avatar asked Feb 12 '16 21:02

ConfusedNoob


1 Answers

When you run npm start, node will look for a scripts object in your package.json file, and run the commands associated with the start key.

In your init.d script you are not running npm start, but instead just running node and passing your server.js file as the first argument (which will run that file).

Most likely, something in your start script is needed in order to run your logging correctly. To solve this, you can either:

  • In your init.d script, cwd to your project root and then run npm start.
  • Look in your package.json to see what else your start script is doing, and add the equivalent to your init.d script.
like image 53
duncanhall Avatar answered Oct 21 '22 01:10

duncanhall