0.1.1 • Published 3 years ago

@navigraph/graylog-client v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

graylog-client

This library was created in order to easily integrate Graylog into a JS client by handling the requests in GELF format for you.

Requirements

In order to make use of the library, your Graylog instance needs to be configured to handle the GELF HTTP input.

Installation

Yarn

yarn add @navigraph/graylog-client

NPM

npm install @navigraph/graylog-client

Usage

Simple

import GraylogClient from 'graylog-client';

const glc = new GraylogClient({
  server: 'https://log.example.org',
  source: 'sample-app',
});

glc.info('An informative message.');
glc.warning('Something is about to happen!');

Advanced

import GraylogClient from 'graylog-client';
import { v4 as uuid } from 'uuid';

interface GraylogExtras {
  facility: string;
  stack: string;
}

const glc = new GraylogClient<GraylogExtras>({
  server: 'https://log.example.org',
  source: 'sample-app',
  idGenerator: uuid,
});

glc.error('An error ocurred in the pizza component!', {
  facility: 'Pizza',
  stack: '* stack trace *',
});

Constructor

PropertyTypeDescriptionRequired
serverstringThe endpoint to which the requests should be sent, including protocol.yes
sourcestringThe client from which the logs are sent.yes
idGeneratorfunctionA generator function that returns a string to use as ID for each log request.no

Typescript

If typescript is used, an optional type generic may be passed to the constructor. This can be used to type the extra information sent with each request (see the Advanced Example for an example implementation), but is not required.

Available methods

The GraylogClient contains multiple convenience methods mapping directly towards syslog's severity levels.

MethodSeverityDescriptionCondition
emergencyEmergencySystem is unusableA panic condition. [1]
alertAlertAction must be taken immediatelyA condition that should be corrected immediately, such as a corrupted system database. [1]
criticalCriticalCritical conditionsHard device errors. [1]
errorErrorError conditions
warningWarningWarning conditions
noticeNoticeNormal but significant conditionsConditions that are not error conditions, but that may require special handling. [1]
infoInformationalInformational messages
debugDebugDebug-level messagesMessages that contain information normally of use only when debugging a program. [1]

Each method may be called with two parameters in accordance with the specification below.

ParameterTypeDescriptionRequired
messagestringThe short (summary) message to display in Graylog.yes
extrasobjectAny extra information, not including the source client. This object may be typed using a generic in the constructor, see Constructor.no

Contributing

For guidelines and useful information, please see CONTRIBUTING.md

License

MIT