• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Graylog2 transport for winston, a nodejs logging module

Build Status

winston-graylog2

A graylog2 transport for winston based on the node-graylog2 Library

Installation

Recently rewritten to use ES6 for better compatibility with Winston@3, so please use only with NodeJS >=6.4.0.

If you need to support older versions of Node, please use a version compatible with ^[email protected].

$ npm install winston
$ npm install winston-graylog2

Usage

var winston = require('winston');
var WinstonGraylog2 = require('winston-graylog2');

var options = { ...<your config options here>... };
winston.add(new WinstonGraylog2(options));

or

var winston
var WinstonGraylog2 = require('winston-graylog2');

var options = { ...<your config options here>... };
var logger = winston.createLogger({
  exitOnError: false,
  transports: [
    new WinstonGraylog2(options),
  ],
});

Options

  • name: Transport name
  • level: Level of messages this transport should log. (default: info)
  • silent: Boolean flag indicating whether to suppress output. (default: false)
  • handleExceptions: Boolean flag, whenever to handle uncaught exceptions. (default: false)
  • exceptionsLevel: Level of exceptions logs when handleExceptions is true. (default: error)
  • graylog:
    • servers; list of graylog2 servers
      • host: your server address (default: localhost)
      • port: your server port (default: 12201)
    • hostname: the name of this host (default: os.hostname())
    • facility: the facility for these log messages (default: "Node.js")
    • bufferSize: max UDP packet size, should never exceed the MTU of your system (default: 1400)
  • staticMeta: meta data to be always used by each logging message, for instance environment (development, staging, live)

Older versions of winston-graylog2 allowed the prelog and processMeta options for pre-processing logs and metadata attached to messages (such as stack traces). Winston 3 has implemented independent, custom formatters for handling these things, and they are no longer supported at the transport level. See the Winston docs for details on formatters.

example:

{
  name: 'Graylog',
  level: 'debug',
  silent: false,
  handleExceptions: false,
  graylog: {
    servers: [{host: 'localhost', port: 12201}, {host: 'remote.host', port: 12201}],
    hostname: 'myServer',
    facility: 'myAwesomeApp',
    bufferSize: 1400
  },
  staticMeta: {env: 'staging'}
}

Upgrading from earlier versions of winston-graylog2

Since [email protected] relies heavily on a very powerful set of formatters there are a few formatting actions that winston-graylog2 no longer needs to do. The two primary cases are the inclusion of a meta object, and converting errors so that the stack trace is included in the log message rather than just the name of the error.

[email protected] includes an excellent formatter for dealing with meta, conveniently named metadata. To use it, you can either grab it from the winston.format object, or use the one on logform.format. See the metadata formatter docs for more details.

For formatting Errors, [email protected] includes the errors formatter. To use it, you can either grab it from the winston.format object, or use the one on logform.format. If you want to include the stack trace in the log message, be sure to pass this formatter the { stack: true } option. See the errrors formatter docs for more details.

In order to get functionality identical to earlier versions of winston-graylog2, use both of these formatters together.

var winston = require('winston');
var { format } = winston;
var WinstonGraylog2 = require('winston-graylog2');

var options = { ...<your config options here>... };
var logger = winston.createLogger({
  exitOnError: false,
  format: format.combine(
    format.errors({ stack: true }),
    format.metadata(),
  ),
  transports: [
    new WinstonGraylog2(options)  ],
});

logger.info({ message: 'this is an info message', answer: 42 });
// or equivalently
logger.info('this is an info message', { answer: 42 });

logger.error({ message: new Error('FakeError'), somenumber: 96 });
// or equivalently
logger.error(new Error('FakeError'), { somenumber: 96 });

Log Levels

Supported log levels, as from node-graylog2, are the following

Winston Level Graylog2 level
emerg emergency
alert alert
crit critical
error error
warning warning
warn warning
notice notice
info info
debug debug

All other possible winston levels, or custom levels, will default to info

More Repositories

1

jose

JSON Object Signing and Encryption library for PHP.
PHP
1,786
star
2

docker-smtp

SMTP docker container
Shell
548
star
3

mockserver

Mock your backends in a matter of seconds. HTTP is King.
JavaScript
351
star
4

cuzzle

This library let's you dump a Guzzle request to a cURL command for debug and log purpose.
PHP
329
star
5

notificator

A very lightweight library to handle notifications the smart way.
PHP
192
star
6

roger

A continuous integration and build server for Docker containers
JavaScript
125
star
7

AB

AB test generator library
PHP
70
star
8

godo

Remote and local execution level 9000: go and do stuff.
Go
52
star
9

coding-challenges

Coding challenges we send out for recruitment
51
star
10

clusterjs

Clusterify your NodeJS applications and deploy without downtimes. Just like that.
JavaScript
35
star
11

NamshiVoyeurBundle

Take screenshots of your website before and after a deployment and then compare them.
PHP
32
star
12

reconfig

JavaScript configurations as they're meant to be. Kinda.
JavaScript
30
star
13

slim-slider

Light-weight, Non-jquery and RTL-supported Slider
JavaScript
29
star
14

shisha

Smoke tests made easy.
JavaScript
20
star
15

node-shell-parser

Parse commands like `ps -aux`, then relax.
JavaScript
14
star
16

keyscannerjs

A library to detect automated keyboard events from external devices (such as a barcode scanner)
JavaScript
14
star
17

docker-node-nginx-pagespeed

A simple container to...well, it's actually not that simple. Use it to run JS apps proxied by nginx. With pagespeed. Yes.
11
star
18

newrelic-winston

JavaScript
10
star
19

node-dock

Stop going crazy with running and killing docker containers. Addictive software ahead.
JavaScript
9
star
20

docker-aws-xray-daemon

AWS X-Ray daemon image
9
star
21

NMAnimatedTabBarItem

A UI library to Animate UITabBar Items
Makefile
9
star
22

node-mysql2-promise

JavaScript
9
star
23

stackdriver-pushgateway

JavaScript
8
star
24

NMMultiUnitRuler

iOS library to select different size units using a Scrollable Ruler
Swift
7
star
25

innovate

Client for the Innovate payment Gateway.
PHP
7
star
26

dollar-dom

JavaScript
6
star
27

nunjucks-setasync

Like set, but for async functions.
JavaScript
6
star
28

coding-standards

To add a newline or not, that is the question!
JavaScript
6
star
29

NMFloatLabelSearchField

A lightweight subclass of UITextField to display floating hint and suggestion list as you type
Swift
6
star
30

docker-akeneo

Docker container for Akeneo PIM
Shell
6
star
31

node-es6-seed

JavaScript
6
star
32

NamshiUtilityBundle

A collection of utilities for Sf2 apps.
PHP
6
star
33

NMLocalizedPhoneCountryView

iOS library to add support for selecting a country and its International Phone code in your app
Swift
6
star
34

PhotoViewJS

Pinch-to-zoom, double tap, pan -- dissect your images!
JavaScript
5
star
35

ng-watchers

Get a count of all the watchers AngularJS set on the current DOM
JavaScript
5
star
36

gvalue

A simple PHP library to convert Google Docs into a KeyValue array.
PHP
5
star
37

node-redis-wrapper

JavaScript
5
star
38

s3-sidecar

A container that works as a volume sidecar within a k8s pod.
Shell
5
star
39

zindex

Stream and transform your data from, to where you want
JavaScript
3
star
40

docker-elasticsearch

ElasticSearch 1.4.0 on Docker until the official dockerfile/elasticsearch image gets updated :)
3
star
41

docker-kibana4

A docker container to run kibana, compatible with found.no.
Shell
3
star
42

gulp-srizer

Add SRI hashes to your assets
JavaScript
3
star
43

smscountry

PHP library to send SMS messages through SMSCountry.
PHP
3
star
44

emailvision

This small library provides support for the "REST" interface exposed by EmailVision.
PHP
3
star
45

node-pubsub-subscriber

JavaScript
3
star
46

countjs

A small utility to count things
JavaScript
3
star
47

utils

Utilities we had to develop (arrays, strings)
PHP
2
star
48

expressjs-utils

JavaScript
2
star
49

preconfig

PHP's port of reconfig (https://github.com/namshi/reconfig)
PHP
2
star
50

qzprinty

A simple utility to print html using qz tray
JavaScript
2
star
51

we-talking-about-practice

We talking about practice, man?!?
2
star
52

lib-logger

JavaScript
1
star
53

gmaps-address-locator

Google maps based utility allowing locating of users addresses
JavaScript
1
star
54

node-file-ensure

Ensures that a file exists: if not, it creates it.
JavaScript
1
star
55

nmPhone

JavaScript
1
star
56

namshi.github.com

CSS
1
star
57

node-nmlogger

JavaScript
1
star
58

python-namutil

Python
1
star
59

js-array-into-object

Convert an array into an object (odd entries are keys, even entries are values)
JavaScript
1
star