Registry / serialization / nsyslog-parser

nsyslog-parser

JSON →
library0.10.1jsnpmunverified

The `nsyslog-parser` library provides a robust and flexible solution for parsing syslog messages in Node.js. It supports widely used syslog formats including RFC 3164 (BSD), RFC 5424 (IETF), and the Common Event Format (CEF) popularized by ArcSight. A key differentiator is its fault-tolerant parsing mechanism, designed to extract as much information as possible from non-standard, erroneous, or malformed messages without throwing errors, making it suitable for environments with diverse and potentially imperfect log sources. As of version 0.10.1, the package is primarily a CommonJS module, offering a single default export as a parser function. While specific release cadence is not explicitly stated, its sub-1.0 version suggests a mature but stable utility for its core parsing functionality.

npm install nsyslog-parser
INSTALL
IMPORT
SIG · NSYSLOG-PARSER
N
nsyslog-parser
serializationjavascriptv0.10.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
import parser from 'nsyslog-parser';
import { parser } from 'nsyslog-parser';
The library primarily exports a default function. Use this for modern ESM projects.
parser
const parser = require('nsyslog-parser');
This is the original CommonJS import style, still fully supported.
parser
import * as parserModule from 'nsyslog-parser'; const parser = parserModule.default || parserModule;
import { parser } from 'nsyslog-parser';
For environments where a direct default import might be ambiguous or transpiled differently, this explicit pattern ensures access to the default export.

This quickstart demonstrates how to import and use the `nsyslog-parser` function to parse various syslog message formats, including BSD, IETF RFC 5424, and CEF. It shows how the parser handles different log line structures and the resulting structured output.

const parser = require('nsyslog-parser'); // Standard BSD message const bsdLine = "<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8"; // IETF (RFC 5424) message, with structured data and chained hostnames const ietfLine = "<110>1 2009-05-03T14:00:39.529966+02:00 host.example.org/relay.example.org syslogd 2138 - [exampleSDID@32473 iut='3' eventSource='Application' eventID='1011'][exampleSDID@32474 iut='4' eventSource='Application' eventID='1012'][ssign VER='0111' RSID='1' SG='0' SPRI='0' GBC='2' FMN='1' CNT='7' HB='K6wzcombEvKJ+UTMcn9bPryAeaU= zrkDcIeaDluypaPCY8WWzwHpPok= zgrWOdpx16ADc7UmckyIFY53icE= XfopJ+S8/hODapiBBCgVQaLqBKg= J67gKMFl/OauTC20ibbydwIlJC8= M5GziVgB6KPY3ERU1HXdSi2vtdw= Wxd/lU7uG/ipEYT9xeqnsfohyH0=' SIGN='AKBbX4J7QkrwuwdbV7Taujk2lvOf8gCgC62We1QYfnrNHz7FzAvdySuMyfM='] BOMAn application event log entry"; // Syslog CEF (Common Event Format) const cefLine = "Jan 18 11:07:53 dsmhost CEF:0|Trend Micro|Deep Security Manager|<DSM version>|600|User Signed In|3|src=10.52.116.160 suser=admin target=admin msg=User signed in from 2001:db8::5"; console.log('BSD Message:', parser(bsdLine)); console.log('IETF Message:', parser(ietfLine)); console.log('CEF Message:', parser(cefLine));
Debug
Known issues
gotchaThe parser is designed to be highly flexible and will attempt to extract information from malformed messages without throwing errors. This behavior means it may silently return partial results or null fields for badly formatted input, potentially masking underlying issues in the log source if the output isn't thoroughly validated by the consumer.
fix
Always inspect the parsed output for expected fields and values, especially when dealing with potentially unreliable log sources, to ensure data integrity and completeness.
affects: >=0.1.0
gotchaAs a pre-1.0 package (version 0.10.1), while the core API is stable, minor versions could introduce breaking changes without adhering to strict semantic versioning. Always review the changelog when updating to a new minor version.
fix
Pin the exact version in your `package.json` (`"nsyslog-parser": "0.10.1"`) or use a tilde `~` for patch updates only (`"nsyslog-parser": "~0.10.1"`), and thoroughly test your application after any upgrade.
affects: <1.0.0
gotchaThe package does not ship with TypeScript type definitions. When used in a TypeScript project, you will need to either declare the module manually or install `@types/nsyslog-parser` if available (though it's unlikely for this specific package).
fix
Create a `declarations.d.ts` file with `declare module 'nsyslog-parser';` or define specific types for the expected parsed output if strict typing is required.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: nsyslog_parser_1.default is not a function
Incorrect ESM import attempting to destructure a named export when the library provides a default export.
fix
Use `import parser from 'nsyslog-parser';` for ESM, or `const parser = require('nsyslog-parser');` for CommonJS.
ReferenceError: require is not defined
Attempting to use `require` in an ESM module context (e.g., in a file with `"type": "module"` in `package.json` or a `.mjs` file).
fix
Switch to ESM import syntax: `import parser from 'nsyslog-parser';`.
The parsed output is missing expected fields (e.g., `host` is null, `message` is empty).
The input syslog message is malformed, uses a non-standard proprietary format, or the parser couldn't confidently extract the information. Due to its fault-tolerant design, it won't throw an error but might return incomplete data.
fix
Inspect the `originalMessage` field in the parsed output and compare it against the expected RFC or CEF format to identify discrepancies. Adjust the log source if possible, or implement custom post-parsing logic to handle specific malformations.
Upgrade
Version history
0.10.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
nsyslog-parser — npm install nsyslog-parser · libregistry