@ngbrown/seq-logging

0.3.1-patch.2 • Public • Published

Seq Logging for JavaScript Build status NPM

This library makes it easy to support Seq from Node.js logging libraries, initially Bunyan via bunyan-seq. It is not expected that applications will interact directly with this package.

Usage

A Logger is configured with serverUrl, and optionally apiKey as well as event and batch size limits.

let process = require('process');
let seq = require('seq-logging');

let logger = new seq.Logger({ serverUrl: 'http://localhost:5341' });

logger.emit({
    timestamp: new Date(),
    level: 'Information',
    messageTemplate: 'Hello for the {n}th time, {user}!',
    properties: {
        user: process.env.USERNAME,
        n: 20
    }
});

logger.close();

Events are sent using the emit() method, that internally performs asynchronous batching based on payload size.

When the application exits, close() ensures all buffered events are written. This can be done at any time otherwise using the flush() method. Both of these methods return promises indicating completion.

When logging from a browser, and the application is being navigated away or closed, a pagehide or unload event listener has limited options and asynchronous methods will usually not succeed. In that case, the application can call flushToBeacon() to queue all remaining buffered events into navigator.sendBeacon(). There is a size limit imposed by browsers so this is a best-effort attempt.

Implementations

  • bunyan-seq - collect events from the Buyan logging framework

Readme

Keywords

Package Sidebar

Install

npm i @ngbrown/seq-logging

Weekly Downloads

0

Version

0.3.1-patch.2

License

Apache-2.0

Unpacked Size

32.9 kB

Total Files

11

Last publish

Collaborators

  • ngbrown