Loggly does not work through Winston on Pi

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

This is a web server running in NodeJS (v4), and I use Winston to log into the Loggly logging service. Everything works well when the project starts via npm start from the terminal (when launched as "pi" or via sudo -s). However, when the project starts at startup, logging does not work, and I cannot understand why.

To start the project at startup, I created the etc / init.d script file. The project starts and serves traffic, everything works fine, except for registration. I see no errors (although registration failed). This is how I run my project from my etc / init.d script:

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

I use winston: https://www.npmjs.com/package/winston and winston-loggly: https://www.npmjs.com/package/winston-loggly .

Any ideas why registration does not work when starting the process at boot?

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"); 
+6
source share
1 answer

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

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

Most likely, something in your start script is necessary for proper logging. To solve this problem, you can:

  • In the init.d script, cwd to the root directory of the project, and then run npm start .
  • See what your start script looks like and add the equivalent to your init.d script.
+2
source

All Articles