A Rsyslog transport for winston.
var winston = require('winston');
//
// Requiring `winston-rsyslog` will expose
// `winston.transports.Rsyslog`
//
require('winston-rsyslog2');
winston.add(winston.transports.Rsyslog, options);
This is a fork of winston-rsyslog
version 0.0.2. See the CHANGELOG for differences.
The rsyslog transport takes the following options:
- level: Level of messages that this transport should log
- host: Host where rsyslog runs (default : localhost)
- port: rsyslog Port (default : 514)
- facility: Facility index (default is 0, valid values are from 0 to 23)
- protocol: TCP or UDP (values can be "T" for TCP, "U" for UDP and detect IP version from host option, "U4" for UDP over IPv4, "U6" for UDP over IPv6, default is "U")
- hostname: The hostname the application is running at (default is the current hostname)
- tag: A tag to name the application for easy log filtering (default is 'winston')
- timeout: Socket timeout for TCP (default is 2000 ms)
- levelMapping: Mapping of level names to rsyslog security levels (defaults to
winston.config.syslog.levelMapping
) - dateProvider: A parameterless function that returns a date string (default is
new Date().toISOString()
) - messageProvider: A function that returns the message string, takes three parameters:
level
,msg
andmeta
(msg
is already formatted by winston)
Through facility parameter, You'll be able to use the right log file on rsyslog:
0 : kernel messages
1 : user-level messages
2 : mail system
3 : system daemons
4 : security/authorization messages
5 : messages generated internally by syslogd
6 : line printer subsystem
7 : network news subsystem
8 : UUCP subsystem
9 : clock daemon
10 : security/authorization messages
11 : FTP daemon
12 : NTP subsystem
13 : log audit
14 : log alert
15 : clock daemon (note 2)
16 : local use 0 (local0)
17 : local use 1 (local1)
18 : local use 2 (local2)
19 : local use 3 (local3)
20 : local use 4 (local4)
21 : local use 5 (local5)
22 : local use 6 (local6)
23 : local use 7 (local7)
To let rsyslog receive data through UDP port, you should change its configuration (typically located in /etc/rsyslog.conf), enabling the following tags:
$ModLoad imudp
$UDPServerRun 514
The first tag enables UDP reception, while the second one defines the listening port.
To enable TCP reception on port 10514 (as an example):
$ModLoad imtcp
$InputTCPServerRun 10514
npm install winston-rsyslog2
All of the winston tests are written in vows, and cover all of the use cases described above. To configure the destination rsyslog daemon parameters, copy the test/config.example.json file into test/config.json and modify it to suite your needs. If no test/config.json file is found, defaults will be used.
Then you can run tests with npm:
npm test