1.0.0 • Published 10 years ago

syslog-protocol v1.0.0

Weekly downloads
3
License
-
Repository
github
Last release
10 years ago

SyslogProtocol.js

NPM version

SyslogProtocol.js is a Syslog (RFC 3164) format parser that supports high-precision timestamps (RFC 3339, ISO 8601).

Given a Syslog message with a high-precision timestamp:

<38>1987-06-18T15:20:30.337Z server sshd[42]: Accepted publickey for user

It'll return the following object (with time being an instance of Date):

{ facility: "auth",
  facilityCode: 4,
  severity: "info",
  severityCode: 6,
  time: new Date("1987-06-18T15:20:30.337Z"),
  host: "server",
  process: "sshd",
  pid: 42,
  message: "Accepted publickey for user" }

Ironically, SyslogProtocol.js does not support plain RFC 3164's timestamps, which are in who-knows-what time zone and lack a year part. If you can, don't use them. If you're really keen on them, please let me know and I'll see about implementing.

Tour

  • Supports RFC 3164 with high-precision timestamps (RFC 3339, ISO 8601).
    For example, Rsyslog's RSYSLOG_ForwardFormat uses those.
  • Supports colon-less TAG/process identifiers/messages (which Heroku log drains send).
  • Facility and severity names are <syslog.h> and syslog(3) compatible.
  • All property names of the returned object have gone through serious sincere consideration and are amazingly well chosen.

Installing

npm install syslog-protocol

Using

Just require SyslogProtocol.js and use its parse function:

var SyslogProtocol = require("syslog-protocol")
var msg = "<38>1987-06-18T15:20:30.337Z server sshd[42]: Accepted publickey"
SyslogProtocol.parse(msg)

Alphanumeric process identifiers

SyslogProtocol.js can also handle alphanumeric process identifiers (sshd[foo]). For example, given Heroku's forwarded log:

<158>1987-06-18T15:20:30.337Z d.550e8400-e29b-41d4-a716-446655440000 heroku[router] at=info method=GET path=/

SyslogProtocol.js will return:

{ facility: "local3",
  facilityCode: 19,
  severity: "info",
  severityCode: 6,
  time: new Date("1987-06-18T15:20:30.337Z"),
  host: "d.550e8400-e29b-41d4-a716-446655440000",
  process: "heroku",
  pid: "router",
  message: "at=info method=GET path=/" }

Properties

The returned object from parse has the following properties:

PropertyDescription
facilityFacility name. See below for a full list of facilities.
facilityCodeFacility numeric code.
severitySeverity name. See below for a full list of severities.
severityCodeSeverity numeric code.
timeDate instance from the timestamp.
hostHostname or IP address.
processProcess name.
pidProcess identifier (taken from brackets after process name). If the message lacks one, pid won't be set at all. If it looks like a number, it'll be cast to Number.
messageRest of the message.

Facilities

Facility names returned by SyslogProtocol.js match <syslog.h> and syslog(3).

CodeFacility
0kern
1user
2mail
3daemon
4auth
5syslog
6lpr
7news
8uucp
9cron
10authpriv
11ftp
12ntp
13logaudit
14logalert
15clock
16local0
17local1
18local2
19local3
20local4
21local5
22local6
23local7

Severities

Severity names returned by SyslogProtocol.js match <syslog.h> and syslog(3).
Blame them for the inconsistent naming.

CodeSeverity
0emerg
1alert
2crit
3err
4warning
5notice
6info
7debug

License

SyslogProtocol.js is released under a Lesser GNU Affero General Public License, which in summary means:

  • You can use this program for no cost.
  • You can use this program for both personal and commercial reasons.
  • You do not have to share your own program's code which uses this program.
  • You have to share modifications (e.g. bug-fixes) you've made to this program.

For more convoluted language, see the LICENSE file.

About

Andri Möll typed this and the code.
Monday Calendar supported the engineering work.

If you find SyslogProtocol.js needs improving, please don't hesitate to type to me now at andri@dot.ee or create an issue online.