A graylog2 transport for winston
npm install winston-graylog2
A convenience wrapper may be supported in the future but for now the
easiest way to use is to instantiate a new winston
logger and add winston-graylog2
as a transport.
var winston = require("winston"),
graylog2 = require("winston-graylog2").Graylog2,
levels = winston.config.syslog.levels;
// Initialize logger
var logger = new (winston.Logger)({
levels: levels,
transports: [new (graylog2)()]
});
// Log something
logger.log('emerg', 'FIX THIS NOW');
logger.emerg('NO RLY');
The default winston logger settings should not be used because Graylog2 expects the log levels to be syslog levels. All else should function the same as other loggers.
By default, the pid
and cwd
are added to the graylog meta fields.
All other meta fields passed to winston get sent along in the meta
data as well.
- host [value]:
'localhost'
- port [value]:
12201
- level [value]:
'info'
- facility [value]:
'winston-graylog2'
- timestamp [value or function]:
function() { ((new Date()).getTime()/1000).toFixed(2); };
(current time in seconds)
- Add chunking to messages
- More pleasant way to flatten meta fields without changing logger api
There is another winston-graylog2 module, http://github.com/flite/winston-graylog2, that was made independently. I opted to keep this repo separate for a few reasons, one of them being that only a subset of the syslog logging levels are exposed in the other project.