A Graylog2 or GELF transport for Winston. Supports HTTP(S) & TCP/TCP over TLS protocols.
As it's written in ES6, this module requires at least node v4.
$ npm install --save winston-log2gelf
const winston = require('winston');
require('winston-log2gelf');
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'info',
handleExceptions: true,
humanReadableUnhandledException: true
}),
new (winston.transports.Log2gelf)({
level: 'info',
host: '192.168.0.15',
port: 12201,
protocol: 'tls',
handleExceptions: true
})
]
});
If used in a script where the process has to naturally exit after its execution, the connection has to be closed (as a db connection would have to) if TCP socket is used. It should be done like so:
logger.transports.log2gelf.end();
name
: Transport namehostname
: The name of this host (default: os.hostname())host
: The GELF server address (default: 127.0.0.1)port
: The GELF server port (default: 12201)protocol
: Protocol used to send data (TCP, TLS [TCP over TLS], HTTP or HTTPS). (default: tcp)level
: Level of messages this transport should log. See winston levels (default: info)silent
: Boolean flag indicating whether to suppress output. (default: false)handleExceptions
: Boolean flag, whenever to handle uncaught exceptions. (default: false)service
: as facility is depreacated, service describes what kind of "service" this is (like MySQLd or Apache2). (default: nodejs)environment
: the environment on which your service is running. (default: development)release
: the version of your service (e.g. 1.0.0).