-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This enforces a 90-column width. Package dependencies were corrected to be explicit (winston-transport) because the linter complains about that. Semver: patch Ref: LOG-7378
- Loading branch information
1 parent
468a439
commit cabd1e5
Showing
3 changed files
with
53 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
// External Libraries | ||
const Transport = require('winston-transport'); | ||
const Logger = require('logdna').Logger; | ||
const stringify = require('json-stringify-safe'); | ||
'use strict' | ||
|
||
// Constants | ||
const DEFAULT_LEVEL = 'debug'; | ||
const DEFAULT_NAME = 'LogDNA'; | ||
const pkg = require('./package.json') | ||
const Transport = require('winston-transport') | ||
const Logger = require('logdna').Logger | ||
|
||
const DEFAULT_LEVEL = 'debug' | ||
const DEFAULT_NAME = 'LogDNA' | ||
|
||
/* | ||
* Support for Winston Transport | ||
*/ | ||
module.exports = class LogDNATransport extends Transport { | ||
constructor(options) { | ||
const pkg = require('./package.json'); | ||
super(options); | ||
this.name = options.name || DEFAULT_NAME; | ||
this.level = options.level || DEFAULT_LEVEL; | ||
this.index_meta = options.index_meta || false; | ||
this.logger = new Logger(options.key, Object.assign({}, options, { | ||
UserAgent: `${pkg.name}/${pkg.version}` | ||
})); | ||
} | ||
|
||
log(info, callback) { | ||
info = info || {}; | ||
constructor(options) { | ||
super(options) | ||
this.name = options.name || DEFAULT_NAME | ||
this.level = options.level || DEFAULT_LEVEL | ||
this.index_meta = options.index_meta || false | ||
this.logger = new Logger(options.key, { | ||
...options | ||
, UserAgent: `${pkg.name}/${pkg.version}` | ||
}) | ||
} | ||
|
||
if (info.error instanceof Error) { | ||
info.error = info.error.stack || info.error.toString(); | ||
} | ||
log(info, callback) { | ||
info = info || {} | ||
|
||
if (!info.message) { | ||
info.message = stringify(info, null, 2, function() { return undefined; }); | ||
} | ||
if (info.error instanceof Error) { | ||
info.error = info.error.stack || info.error.toString() | ||
} | ||
|
||
const { level, message, index_meta, ...meta } = info; | ||
const opts = { | ||
level: level | ||
, index_meta: typeof info.index_meta === 'boolean' ? index_meta : this.index_meta | ||
, context: meta || {} | ||
}; | ||
if (!info.message) { | ||
info.message = JSON.stringify(info, null, 2, function() { return undefined }) | ||
} | ||
|
||
this.logger.log(message, opts); | ||
if (callback) { callback(null, true); } | ||
const {level, message, index_meta, ...meta} = info | ||
const opts = { | ||
level: level | ||
, index_meta: typeof info.index_meta === 'boolean' ? index_meta : this.index_meta | ||
, context: meta || {} | ||
} | ||
}; | ||
|
||
this.logger.log(message, opts) | ||
if (callback) { callback(null, true) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters