https://github.com/dial-once/node-logtify-bugsnag
Bugsnag execution chain link for node-logtify logger
https://github.com/dial-once/node-logtify-bugsnag
Last synced: about 2 months ago
JSON representation
Bugsnag execution chain link for node-logtify logger
- Host: GitHub
- URL: https://github.com/dial-once/node-logtify-bugsnag
- Owner: dial-once
- License: mit
- Created: 2017-05-11T15:56:40.000Z (about 8 years ago)
- Default Branch: develop
- Last Pushed: 2018-11-30T08:50:33.000Z (over 6 years ago)
- Last Synced: 2025-03-23T02:28:26.684Z (2 months ago)
- Language: JavaScript
- Size: 70.3 KB
- Stars: 1
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logtify-bugsnag
[](http://sonar.dialonce.net/dashboard?id=node-logtify-bugsnag)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-bugsnag)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-bugsnag)
[](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify-bugsnag&metric=coverage)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-bugsnag)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-bugsnag)Bugsnag execution subscriber for [logtify](https://github.com/dial-once/node-logtify) logger
## Installation
```
npm i -S logtify-bugsnag
```## Usage
Used with [logtify](https://github.com/dial-once/node-logtify) module.```js
require('logtify-bugsnag')({ BUGS_TOKEN: 'YOUR_BUGSNAG_TOKEN' });
const { notifier } = require('logtify')();notifier.notify(new Error('Test error'));
notifier.notify('Hello world!');
```__BEWARE!!__
```js
// if required after subscriber, adapter will be undefined
let { notifier } = require('logtify')();
require('logtify-bugsnag')({ BUGS_TOKEN: 'YOUR_BUGSNAG_TOKEN' });
// notifier is undefined// So, you need to refresh the logtify module:
let { notifier } = require('logtify')();// typeof notifier === 'object'
notifier.notify(new Error('Test error'));
notifier.notify('Hello world!');
```However you can overcome it if you use plain ES5 require syntax:
```js
const logtify = require('logtify')();
require('logtify-bugsnag')({ BUGS_TOKEN: 'YOUR_BUGSNAG_TOKEN' });
const notifier = logtify.notifier;// typeof notifier === 'object'
notifier.notify(new Error('Test error'));
notifier.notify('Hello world!');
```The subscriber will make sure that a message will be sent to Bugsnag if:
* ``message.level === 'error'``
* ``process.env.BUGSNAG_LOGGING === 'true' || settings.BUGSNAG_LOGGING === true``To set the message.level to be ``error``, make sure to use one of the following:
```js
const { stream, logger } = require('logtify')();stream.log('error', new Error('Hello world'), { my: 'metadata' }); // error can also be passed as an arg
logger.log('error', 'Hello world', { my: 'metadata' }); // or a string
logger.error('Hello world', { my: 'metadata'});
```
Or with a ``BugsnagAdapter``:
```js
const { notifier } = require('logtify')();notifier.notify('Hello world');
```An adapter also exposes standard bugsnag's ``requestHandler`` and ``errorHandler``:
```js
require('logtify-bugsnag')();
const { notifier } = require('logtify')();notifier.requestHandler;
notifier.errorHandler;
```## Configuration
* ``process.env.BUGSNAG_LOGGING = 'true' || BUGSNAG_LOGGING: true`` - Switching on / off the subscriber and adapter. On by default
* ``process.env.BUGS_TOKEN = 'TOKEN' || BUGS_TOKEN: 'TOKEN'`` - your Bugsnag token
* ``process.env.BUGSNAG_RELEASE_STAGES = 'production,staging'`` - comma separated list of bugsnag release stages**Settings**:
Module can be configured by both env variables or config object. However, env variables have a higher priority.
```js
{
BUGSNAG_LOGGING: true|false
BUGS_TOKEN: 'YOUR_BUGSNAG_TOKEN'
BUGSNAG_RELEASE_STAGES: ''
BUGSNAG_APP_VERSION: '1.2.3'
LOG_TIMESTAMP = 'true'
LOG_ENVIRONMENT = 'true'
LOG_LEVEL = 'true'
LOG_REQID = 'true' // only included when provided with metadata
LOG_CALLER_PREFIX = 'true' // additional prefix with info about caller module/project/function
}
```