You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

winston-graylog2-extended-metadata

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-graylog2-extended-metadata

A fork of winston-graylog2. Includes sending all properties from the log object as separate fields in the Graylog.


Version published
Weekly downloads
159
decreased by-31.47%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Build Status

winston-graylog2-metadata

A fork of winston-graylog2. Includes sending all properties from the log object as separate fields in Graylog.

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 ^winston-graylog2@1.1.0.

$ 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 winston@3.x 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.

winston@3.x 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, winston@3.2.0 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 LevelGraylog2 level
emergemergency
alertalert
critcritical
errorerror
warningwarning
warnwarning
noticenotice
infoinfo
debugdebug

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

FAQs

Package last updated on 08 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc