Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binded/winston-rollbar-transport
A winston logger transport for Rollbar
https://github.com/binded/winston-rollbar-transport
Last synced: about 4 hours ago
JSON representation
A winston logger transport for Rollbar
- Host: GitHub
- URL: https://github.com/binded/winston-rollbar-transport
- Owner: binded
- License: mit
- Created: 2016-10-23T01:49:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-23T03:01:14.000Z (about 8 years ago)
- Last Synced: 2023-12-25T13:12:07.661Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 9
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# winston-rollbar-transport
[![Build Status](https://travis-ci.org/blockai/winston-rollbar-transport.svg?branch=master)](https://travis-ci.org/blockai/winston-rollbar-transport)
A [winston](https://github.com/winstonjs/winston) logger transport for
[Rollbar](https://github.com/rollbar/node_rollbar).## Install
```bash
npm install --save winston-rollbar-transport winston
```Requires Node v6+
## Usage
```javascript
import winston from 'winston'
import RollbarTransport from 'winston-rollbar-transport'const logger = new winston.Logger({
transports: [
new RollbarTransport({
// required
rollbarAccessToken: process.env.ROLLBAR_ACCESS_TOKEN,
rollbarConfig: {
// optional
// see https://github.com/rollbar/node_rollbar#configuration-reference
},
level: 'info', // log level. defaults to 'info'
}),
],
})// regular logging
logger.info('some message')// logging with custom metadata
logger.info('some message', {
// req and err are special keys, see below
somekey: 'somevalue',
})// logging with request data
logger.info('some message', { req })// logging an error
// Important: the second parameter is not optional (see below)
logger.error(err, { err })
```### Error handling
Since Winston log messages are converted to strings,
`winston-rollbar-transport` will only see a string if `logger.error(new
Error())` is called and can't therefore report the exception propoerly
to Rollbar with `rollbar.handleErrorWithPayloadData`.Therefore, to correctly report exceptions, use the `err` key on the meta
field in addition to the message. For example:```javascript
logger.error(err, { err })
```### Using with console transport
If you are using this with the `console` transport, you might want to
disable printing the meta objects so that you don't see the whole
`req` object when its set:```javacript
new winston.transports.Console({
prettyPrint: () => '', // disables printing the meta object
})
```See [./test](./test) directory for usage examples.