npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

syslog-streams2

v1.1.1

Published

Streams2 implementation that inputs plain strings, bunyan records, glossy records, and outputs syslog formatted strings

Downloads

51

Readme

Syslog-Streams2

Syslog protocol as a Node Transform stream.

Usage

var SyslogStream = require('syslog-streams2');
var stream = new SyslogStream();
stream.write('foo');

Options

Some options are supported:

new SyslogStream({
	decodeBuffers: <boolean>,
	decodeStrings: <boolean>,
	useStructuredData: <boolean>,
	defaultSeverity: <string>,
	PEN: <integer>,
	
	type: <string>,
	facility: <string>,
	{host|hostname}: <string>,
	{name|appName}: <string>,
	{msgId|msgID}: <string>,
	pid: <integer>
});

The first set of options apply to the stream itself and how it handles incoming data. The second set of options are curried into the glossy instance that performs the translation.

decodeBuffers

True to decode buffers written to the stream; false to do nothing. You should be writing objects to the stream, but it could be handy when piping from other locations. Defaults to false.

decodeJSON

True to attempt to decode strings as JSON; false to do nothing. May be used in conjunction with decodeBuffers. Defaults to false.

useStructuredData

True to attempt to encode structured data; false to do nothing. Defaults to true unless 'type' is set (more on that below).

defaultSeverity

The default severity of a log message, if not specified. This is used for all messages interpreted as strings or invalid bunyan/glossy records, and bunyan or glossy records that do not specify a level/severity.

PEN

If you have a Private Enterprise Number, specify it here. Non-standardized structured data is tagged with your PEN. To strictly conform to the spec, you should not use this unless you have registered a PEN with IANA.

type

This is passed along to glossy to specify what type of output to create. Right now, 'BSD' is the only valid option, to be used if you want to output 'old style' RFC3164-compatible messages. Leave empty for RFC5424-style messages. Glossy's documentation mentions RFC 5848, but no references currently exist in the code, so these are the only two options.

facility

The facility to log to. Case insensitive. Defaults to local0. Can be overridden in .write().

Valid facilities are:

KERN - Kernel messages
USER - User-level messages
MAIL - Mail system
DAEMON - System daemons
AUTH - Security/authorization messages
SYSLOG - Messages generated internally by syslogd
LPR - Line printer subsystem
NEWS - Network news subsystem
UUCP - UUCP subsystem
CLOCK - Clock daemon
SEC - Security/authorization messages
FTP - FTP daemon
NTP - NTP subsystem
AUDIT - Log audit
ALERT - Log alert
LOCAL0 - Local use 0
LOCAL1 - Local use 1
LOCAL2 - Local use 2
LOCAL3 - Local use 3
LOCAL4 - Local use 4
LOCAL5 - Local use 5
LOCAL6 - Local use 6
LOCAL7 - Local use 7

host / hostname

The hostname of the system generating the log message. Defaults to os.hostname(), falls back on the nil value(-). Can be overriden in .write().

From RFC5424:

The HOSTNAME field SHOULD contain the hostname and the domain name of
the originator in the format specified in STD 13 [RFC1034].  This
format is called a Fully Qualified Domain Name (FQDN) in this
document.

In practice, not all syslog applications are able to provide an FQDN.
As such, other values MAY also be present in HOSTNAME.  This document
makes provisions for using other values in such situations.  A syslog
application SHOULD provide the most specific available value first.
The order of preference for the contents of the HOSTNAME field is as
follows:
	
1. FQDN
2. Static IP address
3. hostname
4. Dynamic IP address
5. the NILVALUE

pid

The process id of the process generating the log message. Defaults to process.pid, falls back on the nil value(-). Can be overridden in .write().

name / appName

The app name to use when logging messages. Defaults to process.title, falls back on process.argv[0] followed by the nil value(-). Can be overriden in .write().

The APP-NAME field SHOULD identify the device or application that
originated the message.  It is a string without further semantics.
It is intended for filtering messages on a relay or collector.

msgId / msgID

The message id to use when logging messages. Defaults to the nil value. Can be overriden in .write().

The MSGID SHOULD identify the type of message.  For example, a
firewall might use the MSGID "TCPIN" for incoming TCP traffic and the
MSGID "TCPOUT" for outgoing TCP traffic.  Messages with the same
MSGID should reflect events of the same semantics.  The MSGID itself
is a string without further semantics.  It is intended for filtering
messages on a relay or collector.  

Notes

Data is handled slightly differently based on the input. Bunyan-style records are identified by the presence of a msg key and validated against Bunyan's record format. Glossy-style records are identified by the presence of a message key and validated against Glossy's record format.

Records that fail validation, or that return false when run through Glossy will be converted to JSON and written as a plain string.

Structured data from Bunyan records

When possible, extra object keys will be processed into structured data. There are two cases where this will happen.

  • When you provide a key matching a defined SDID in the RFC, such as 'timeQuality', 'origin', or 'meta'
  • When you provide a PEN

Note: Object properties that do not contain objects cannot be converted to structured data (e.g. { custom: 'foo', msg: 'hello' }; neither can properties with keys that violate the acceptable characters for an SDID, e.g. { 'foo@bar': 'baz', msg: 'hello' }.

Standardized SDIDs will be validated and converted. Any remaining keys will be treated as custom structured data and formatted with your PEN.

Example:

log.write({ meta: { ip: '127.1.1.1' }, msg: 'hello' })

outputs:

<149>1 2014-12-05T23:01:36.170Z myndzi node 20465 - [meta ip="127.1.1.1"] hello

while

log.write({ custom: { key: 'val' }, msg: 'hello' })

outputs:

<149>1 2014-12-05T23:03:58.957Z myndzi node 20492 - [custom@32473 key="val"] hello

Structured data from Glossy records

In general, the same as above, with the exception that glossy's format makes structured data explicit in its structure, so no "implying" is done by exclusion in the way that it is done for Bunyan.

Tests

Clone and run npm test. Currently 75 tests and 100% coverage.