node-graylog
Graylog2 client library for Node.js
Synopsis
require("graylog");
Short message:
log("What we've got here is...failure to communicate");
Long message:
log("What we've got here is...failure to communicate", "Some men you just
can't reach. So you get what we had here last week, which is the way he wants
it... well, he gets it. I don't like it any more than you men.");
Short with options:
log("What we've got here is...failure to communicate", { level: LOG_DEBUG });
Long with options:
log("What we've got here is...failure to communicate", "Some men you just
can't reach. So you get what we had here last week, which is the way he wants
it... well, he gets it. I don't like it any more than you men.",
{
facility: "Steve Martin"
}
);
You can add custom fields to the options:
log("What we've got here", {
level: LOG_DEBUG,
_failure: "to communicate"
});
Options
facility
- by default it's set to GLOBAL.graylogFacility
.level
- syslog levels, one of: LOG_EMERG
, LOG_ALERT
, LOG_CRIT
, LOG_ERR
, LOG_WARNING
, LOG_NOTICE
, LOG_INFO
(default), LOG_DEBUG
.timestamp
- unixtime of log event, by default it's now.host
- by default, it's auto detected.stack
- if set to true
, log will contain source file name and line number.
Additional settings
You can set GLOBAL.graylogHost
and GLOBAL.graylogPort
to the host and port of the Graylog2 server. By defaults it's localhost
and 12201
.
You can set GLOBAL.graylogToConsole
to true
to log JSON entries to console as well (useful for development in case you don't want to have graylog2 running on your workstation).
You should set GLOBAL.graylogFacility
to the name of your application. By default it's set to "Node.js".
You can set GLOBAL.graylogSequence
to a integer non-zero value (set it to 1) to have an auto-incremented _graylogSequence
field sent to graylog with each log entry. Due to the fact that UDP packets are not guaranteed to be received in the same order as sent, you might need a sequence number to recover the course of events.
Example
See sayHello.js
.
Modification of the GLOBAL object?! But why?
I know, it's wrong. However I like it that way and I truly believe that logger function must be the easiest to call for the programmer to never hesitate using it. So I think that logger functions should be one of the extremely few cases where global namespace pollution is feasible.
What is graylog2 after all?
It's a miracle. Get it at http://www.graylog2.org/
Installation
npm install .
TODO
- Limit messages size to MTU size?..
License
See LICENSE file. Basically, it's a kind of "do-whatever-you-want-for-free" license.
Author
Egor Egorov me@egorfine.com
Contributors
- danlangford (dan L)
- andris9