Syslogh.js is a library for logging to your system's Syslog (RFC
3164) from within Node.js. It provides simple native bindings to
<syslog.h> and syslog(3). You're in luck, because
it does not come with any bells and whistles. Intentionally. KISS, right?
Works with Node v0.10, v0.11, v0.12 and of course v4 (stable).
Using it in production with Monday Calendar, so will be kept up to
date when new Node versions come out.
Installing
Install with: npm install syslogh
Using
Using Syslogh.js is similar to using syslog(3) from C/C++.
First use openlog with your app name (up to 255 characters), options and the
facility:
var Syslogh = require("syslogh")Syslogh.openlog("myapp", Syslogh.PID, Syslogh.LOCAL7)
Then, when logging, just pass in the severity and your
message.
Just like with regular syslog(3), you can use sprintf style
placeholders. Those internally use Node's built-in Util.format.
You can also call Syslogh.closelog to close things down, but I'm not sure why
you should bother. :-) Exiting your Node.js program will most likely shut
everything down, too.
The syslog(3) manpage also talks about setlogmask to filter
logs before they're sent. This isn't implemented. Not yet, at least.
Facilities to pass to openlog come from <syslog.h> and (RFC
3164).
Some facilities might differ between systems. For your own app use, best stick
to LOCAL* facilities.