Skip to content

tcichowicz/winston-rsyslog

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

winston-rsyslog

An Rsyslog transport for winston.

Usage

  var winston = require('winston');

  //
  // Requiring `winston-rsyslog` will expose 
  // `winston.transports.Rsyslog`
  //
  require('winston-rsyslog');

  winston.add(winston.transports.Rsyslog, options);

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 is 514)
  • facility: Facility index (default is 0, valid values are from 0 to 23)
  • protocol: TCP or UDP (values can be "T" or "U" accordingly, 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 and meta (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)

Enabling rsyslog

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

Motivation

Just for fun, while learning NodeJS. This (simple) project is based on winston-loggly (thanks @indexzero for the inspiration).

Installation

Installing npm (node package manager)

  $ curl http://npmjs.org/install.sh | sh

Installing winston-rsyslog

  $ npm install winston
  $ npm install winston-rsyslog

Run Tests

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

Author: [Fabio Grande] (http://about.me/fgrande)

License: MIT

About

An rsyslog transport for winston

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • JavaScript 100.0%