# winston-graylog2

> A graylog2 transport for winston

Latest version **2.1.2** (published 2019-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install winston-graylog2
pnpm add winston-graylog2
yarn add winston-graylog2
bun add winston-graylog2
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2019-02-17 |
| First published | 2012-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 6.4.0 |
| Dependencies | 3 |
| Unpacked size | 18.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 128 |
| Author | Started by: Flite, Inc. http://www.flite.com, mantained by: Namshi http://namshi.com |
| Maintainers | odino, smithclay, unlucio |
| Keywords | logging, sysadmin, tools, winston, graylog2 |

## Links

- npm: https://www.npmjs.com/package/winston-graylog2
- Repository: https://github.com/flite/winston-graylog2
- Homepage: https://github.com/flite/winston-graylog2#readme
- Issues: https://github.com/flite/winston-graylog2/issues
- npm.io page: https://npm.io/package/winston-graylog2

## Dependencies (3)

- [winston](https://npm.io/package/winston.md) ^3.2.0
- [graylog2](https://npm.io/package/graylog2.md) ^0.2.1
- [winston-transport](https://npm.io/package/winston-transport.md) ^4.3.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 2.1.2 (latest) — 2019-02-17
- 2.1.1 — 2019-01-29
- 2.1.0 — 2019-01-29
- 2.0.0 — 2019-01-28
- 1.1.0 — 2018-12-18
- 1.0.3 — 2018-08-30
- 1.0.2 — 2018-08-29
- 1.0.1 — 2018-08-28
- 1.0.0 — 2018-03-27
- 0.7.1 — 2018-03-05
- 0.7.0 — 2017-09-19
- 0.6.0 — 2017-01-17
- 0.5.2 — 2016-10-24
- 0.5.1 — 2016-06-28
- 0.5.0 — 2016-05-30
- … 18 more at https://npm.io/package/winston-graylog2/versions

## README

[![Build Status](https://secure.travis-ci.org/namshi/winston-graylog2.png)](http://travis-ci.org/namshi/winston-graylog2)

# winston-graylog2 

A [graylog2][0] transport for [winston][1] based on the [node-graylog2][2] 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`.


``` sh
$ npm install winston
$ npm install winston-graylog2
```

## Usage
```javascript
var winston = require('winston');
var WinstonGraylog2 = require('winston-graylog2');

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

or

```javascript
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.](https://github.com/winstonjs/winston#formats)

example:

```javascript
{
  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](https://github.com/winstonjs/logform/tree/2.1.0#metadata)
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](https://github.com/winstonjs/logform/tree/2.1.0#errors)
for more details.

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

```javascript
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][2], 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`**

[0]: http://www.graylog2.org
[1]: https://github.com/flatiron/winston
[2]: https://github.com/Wizcorp/node-graylog2

---
_Source: https://npm.io/package/winston-graylog2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
