logdna-winston
Advanced tools
Comparing version 1.0.0 to 2.0.0
64
index.js
@@ -1,5 +0,4 @@ | ||
var util = require('util'); | ||
var winston = require('winston'); | ||
var Logger = require('logdna').Logger; | ||
var stringify = require('json-stringify-safe'); | ||
const Transport = require('winston-transport'); | ||
const Logger = require('logdna').Logger; | ||
const stringify = require('json-stringify-safe'); | ||
@@ -9,42 +8,27 @@ /* | ||
*/ | ||
var WinstonTransport = exports.WinstonTransport = function(options) { | ||
this.name = options.name || 'LogDNA'; | ||
this.level = options.level || ''; | ||
winston.Transport.call(this, options); | ||
this.logger = new Logger(options.key, options); | ||
}; | ||
module.exports = class LogDNATransport extends Transport { | ||
constructor(options) { | ||
super(options); | ||
this.name = options.name || 'LogDNA'; | ||
this.level = options.level || ''; | ||
this.logger = new Logger(options.key, options); | ||
this.index_meta = options.index_meta || false; | ||
} | ||
util.inherits(WinstonTransport, winston.Transport); | ||
log(level, msg, meta, callback) { | ||
if (meta instanceof Error) { meta = { error: meta.stack || meta.toString() }; } | ||
winston.transports.Logdna = WinstonTransport; | ||
WinstonTransport.prototype.log = function(level, msg, meta, callback) { | ||
if (meta instanceof Error) { meta = { error: meta.stack || meta.toString() }; } | ||
if (!msg && !(Object.keys(meta).length === 0 && meta.constructor === Object)) { | ||
msg = stringify(meta, null, 2, function() { return undefined; }); | ||
if (!msg && !(Object.keys(meta).length === 0 && meta.constructor === Object)) { | ||
msg = stringify(meta, null, 2, function() { return undefined; }); | ||
} | ||
meta = meta || {}; | ||
let opts = { | ||
level: level | ||
, index_meta: meta.index_meta || this.index_meta | ||
, context: meta | ||
}; | ||
this.logger.log(msg, opts); | ||
if (callback) { callback(null, true); } | ||
} | ||
meta = meta || {}; | ||
var opts = { | ||
level: level | ||
, index_meta: meta.index_meta || false | ||
, context: meta | ||
}; | ||
this.logger.log(msg, opts); | ||
if (callback) { callback(null, true); } | ||
}; | ||
WinstonTransport.prototype.logException = function(msg, meta, callback) { | ||
if (meta instanceof Error) { meta = { error: meta.stack || meta.toString() }; } | ||
if (!msg && !(Object.keys(meta).length === 0 && meta.constructor === Object)) { | ||
msg = stringify(meta, null, 2, function() { return undefined; }); | ||
} | ||
meta = meta || {}; | ||
var opts = { | ||
level: 'error' | ||
, index_meta: meta.index_meta || false | ||
, context: meta | ||
}; | ||
this.logger.log(msg, opts); | ||
}; |
{ | ||
"name": "logdna-winston", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "LogDNA's Node.js logging module with support for Winston", | ||
@@ -41,4 +41,4 @@ "main": "index.js", | ||
"logdna": "^2.0.0", | ||
"winston": "^2.4.0" | ||
"winston": "^3.2.1" | ||
} | ||
} |
@@ -21,3 +21,3 @@ <p align="center"> | ||
```javascript | ||
$ npm install --save logdna-bunyan | ||
$ npm install --save logdna-winston | ||
``` | ||
@@ -34,5 +34,6 @@ | ||
```javascript | ||
var logdna = require('logdna-winston'); | ||
var winston = require('winston'); | ||
var options = { | ||
const logdnaWinston = require('logdna-winston'); | ||
const winston = require('winston'); | ||
const logger = winston.createLogger({}); | ||
const options = { | ||
key: apikey, | ||
@@ -43,12 +44,21 @@ hostname: myHostname, | ||
app: appName, | ||
env: envName | ||
env: envName, | ||
index_meta: true // Defaults to false, when true ensures meta object will be searchable | ||
}; | ||
// Defaults to false, when true ensures meta object will be searchable | ||
options.index_meta = true; | ||
// Only add this line in order to track exceptions | ||
options.handleExceptions = true; | ||
winston.add(winston.transports.Logdna, options); | ||
logger.add(new logdnaWinston(options)); | ||
let meta = { | ||
data:'Some information' | ||
}; | ||
logger.log('info', 'Log from LogDNA-winston', meta); | ||
logger.log('debug', 'Log from LogDNA-winston', meta); | ||
logger.log('warn', 'Log from LogDNA-winston', meta); | ||
logger.log('error', 'Log from LogDNA-winston', meta); | ||
logger.info('Info: Log from LogDNA-winston', meta); | ||
logger.warn('Warn: Log from LogDNA-winston', meta); | ||
logger.error('Error: Log from LogDNA-winston', meta); | ||
``` | ||
@@ -55,0 +65,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68
5008
29
+ Added@colors/colors@1.6.0(transitive)
+ Added@dabh/diagnostics@2.0.3(transitive)
+ Added@types/triple-beam@1.3.5(transitive)
+ Addedasync@3.2.6(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedcolorspace@1.1.4(transitive)
+ Addedenabled@2.0.0(transitive)
+ Addedfecha@4.2.3(transitive)
+ Addedfn.name@1.1.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedkuler@2.0.0(transitive)
+ Addedlogform@2.7.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedone-time@1.0.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtext-hex@1.0.0(transitive)
+ Addedtriple-beam@1.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwinston@3.17.0(transitive)
+ Addedwinston-transport@4.9.0(transitive)
- Removedasync@2.6.4(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedlodash@4.17.21(transitive)
- Removedwinston@2.4.7(transitive)
Updatedwinston@^3.2.1