Manage logs with bunyan and loggly.
npm install yet-another-logger```
npm install --save yet-another-logger
Central logger file, lets call logger.js
`javascript
const logManager = require('yet-another-logger');
const logglyConfig = {
token: 'secret-token',
subdomain: 'subdomain name'
};
global.l = logManager(logglyConfig).loggerFactory({ name: 'app' });
`
Some other file
`javascript
process.env.NODE_ENV = 'test';
const _ = require('lodash');
const chai = require('chai');
const expect = chai.expect;
after(function(done) {
this.timeout(20 * 1000);
console.log(l.getWaiting()) // prints number of logs waiting for confirmation from loggly
l.onAllLogsReceived(done);
});
describe('foo', function() {
this.timeout(10 * 1000);
describe('foo.search', function() {
it('should work', async function() {
let res;
try { res = foo.search() } catch(e) { log.error(e); }
l.info('foo.search', res);
});
});
});
`Documentation
EventEmitterCreates an instance of the LogManager class
EventEmitterEventEmitter - https://www.loggly.com/docs/node-js-logs/
- https://github.com/trentm/node-bunyan
* LogManager ⇐ EventEmitter
* [.bunyanFactory([options], [cb])](#LogManager+bunyanFactory)
* [.loggerFactory([options], [cb])](#LogManager+loggerFactory)
Kind: instance method of LogManager
| Param | Type | Default |
| --- | --- | --- |
| [options] | Object | {} |
| [cb] | function | noop |
Kind: instance method of LogManager
| Param | Type | Default |
| --- | --- | --- |
| [options] | Object | {} |
| [cb] | function | |
Kind: global function
See: LogManager
| Param | Type | Default |
| --- | --- | --- |
| logglyConfig | Object | |
| logglyConfig.token | String | |
| logglyConfig.subdomain | String | |
| [options] | Object | |
| [options.logToStdoutInDev] | Boolean | true |