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

sd-journald

v0.4.0

Published

A portable library to log via the journald socket

Downloads

741

Readme

Minimal wrapper to log to journald

NPM Version Build codecov

Documentation

Installation

Yarn

yarn add sd-journald

npm

npm i sd-journald --save

Interface:

import { Map as ImmutableMap } from 'immutable';
declare enum SyslogPrority {
    EMERG = 0,
    ALERT = 1,
    CRIT = 2,
    ERR = 3,
    ERROR = 3,
    WARNING = 4,
    WARN = 4,
    NOTICE = 5,
    INFO = 6,
    DEBUG = 7
}
declare class Journald {
    syslog_identifier: string;
    socket: Socket | null;
    constructor(syslog_identifier?: string);
    /**
     * This sends a mesage to journald. A syslog priority is required.
     */
    send(priority: SyslogPrority, message: string, kv: ImmutableMap<string, string> | null): void;
}
default journald = new Journald();
declare function send(priority: SyslogPrority, message: string, kv: ImmutableMap<string, string> | null): void;

The default export is an instance of journald. The syslog identifier by default is set to process.argv0, and it can be changed. There are several strict assertions that prevent the user from sending bad data to journald. You must the total size of the message is under 1MB. You must ensure that the keys start with A-Z, and only contain the letters underscore, A-Z, and 0-9. It will be automatically upcased.

Logging is performed synchronously due to a limitation with the underlying library unix-dgram.

Examples

Typescript

Basic usage example:

import journald, { SyslogPrority } from 'sd-journald'

/* Sending an unstructured message */
journald.send(SyslogPrority.INFO, "Test message")

Sending structured message:

import journald, { SyslogPrority } from 'sd-journald'
import { Map as ImmutableMap } from 'immutable'

journald.send(SyslogPrority.INFO, "Test message", new ImmutableMap({"key": "value"}))

Vanilla Javascript

// TODO: Can someone please fill this in?

Why?

This module has been written after because the alternative model has a dependency on libsystemd for compilaton. This means that you cannot build it on Mac OS. Although journald is not available on Mac OS, the idea is that this is a minimal library, and in the future may support remote destinations like systemd-journald-remote. It is meant to provide as low level as possible of an interface to systemd-journald writing without losing many features.