Glossy Syslog Parser and Producer
Glossy is a lightweight JavaScript library designed for parsing and producing raw syslog messages. It supports multiple RFC standards including RFC 3164, RFC 5424, and RFC 5848. The library is unique in that it performs no network interactions itself, leaving the integration with UDP or TCP to the developer. It boasts zero external dependencies and was designed to be operable in various JavaScript environments, including browsers, in addition to Node.js. The current stable version, 0.1.7, was published 11 years ago, indicating an abandoned status. Its primary differentiators were its RFC compliance, dependency-free nature, and flexibility in deployment, though its age now presents significant compatibility challenges with modern JavaScript ecosystems.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use `require()` in an ES Module context (e.g., in a file with `"type": "module"` in package.json or a `.mjs` file).fixEnsure your file is treated as a CommonJS module (e.g., `.js` file without `"type": "module"` in package.json), or use dynamic `import('glossy').then(({ Parse }) => ...)` if you need to use `glossy` within an ESM context. -
TypeError: glossy.Parse.parse is not a function
cause Incorrectly importing or accessing the `Parse` object, possibly trying to call `parse` on the main `glossy` export instead of the `Parse` object.fixEnsure you are correctly destructuring `Parse` from the `require` statement: `const { Parse } = require('glossy');` then call `Parse.parse(...)`.
Warnings
- breaking The `glossy` package is effectively abandoned, with its last release over 11 years ago. This means it is unlikely to receive updates for security vulnerabilities, bug fixes, or compatibility with modern Node.js versions or JavaScript language features. It also lacks official TypeScript types, though community types exist (`@types/glossy`).
- gotcha When producing syslog messages, `glossy.Produce` defaults to the newer RFC 5424 format unless explicitly configured for BSD/RFC 3164 style. This can lead to compatibility issues with older syslog consumers or relays that are not expecting the RFC 5424 format.
- gotcha The library primarily uses CommonJS `require()` syntax. Direct `import` statements (ESM) will not work without a build step (like Webpack or Rollup) or specific Node.js configuration (`"type": "module"` with CJS interoperability settings).
- gotcha Binding to privileged ports (like UDP port 514 for syslog) requires elevated permissions on most operating systems. Running a Node.js application as root introduces security risks.
Install
-
npm install glossy -
yarn add glossy -
pnpm add glossy
Imports
- Parse
import { Parse } from 'glossy';const { Parse } = require('glossy'); - Produce
import Produce from 'glossy';
const { Produce } = require('glossy'); - glossy.info
import { info } from 'glossy';const glossy = require('glossy'); const infoMsg = glossy.info({ message: 'Info Message' });
Quickstart
const { Parse } = require('glossy');
const dgram = require('dgram');
const server = dgram.createSocket('udp4');
server.on('message', function(rawMessage) {
// rawMessage is a Buffer, convert it to a UTF-8 string
Parse.parse(rawMessage.toString('utf8', 0), function(parsedMessage){
console.log(`Received syslog from ${parsedMessage.host} - Message: ${parsedMessage.message}`);
});
});
server.on('listening', function() {
const address = server.address();
console.log(`Syslog server listening on ${address.address}:${address.port}`);
});
// Note: Binding to ports < 1024 often requires elevated privileges (e.g., sudo/root).
// For non-root operation, use a port >= 1024.
server.bind(514, '0.0.0.0', () => {
console.log('Attempting to bind UDP server to port 514');
});