Skip to content

Commit

Permalink
add new option setSource: false
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Jul 28, 2016
1 parent fa91d5b commit 51d7a04
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ var Logsene = function (options) {
if (!options.flushOnExit) {
options.flushOnExit = true
}
this.logsene_debug=options.logsene_debug

this.setSource = options.setLogSource
if (options.hasOwnProperty('setSource')) {
this.setSource = options.setSource
} else {
this.setSource = true
}
this.logsene_debug = options.logsene_debug
this.handleExceptions = options.handleExceptions
this.exitOnError = options.exitOnError
this.flatOptions = options.flatOptions || {safe: true, delimiter: '_'}
Expand All @@ -23,6 +30,7 @@ var Logsene = function (options) {
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false
this.label = options.label || null
this.source = options.source || (process.mainModule ? null : _dirname(process.mainModule.filename)) || module.filename

this.rewriter = options.rewriter || null
if (this.json) {
this.stringify = options.stringify || function (obj) {
Expand All @@ -40,7 +48,7 @@ var Logsene = function (options) {
self.emit('logged', data)
self.emit('flush', data)
})
var logseneExitHandler = function (code) {
var logseneExitHandler = function (code) {
this.logger.once('log', function () {
process.exit(code)
})
Expand All @@ -51,7 +59,7 @@ var Logsene = function (options) {
}.bind(this)
if (options.flushOnExit) {
process.once('SIGTERM', logseneExitHandler)
process.once('SIGINT', logseneExitHandler)
process.once('SIGINT', logseneExitHandler)
process.once('SIGQUIT', logseneExitHandler)
process.once('beforeExit', logseneExitHandler)
}
Expand All @@ -67,7 +75,7 @@ var Logsene = function (options) {
},
configurable: true,
writable: true
})
})
}
}

Expand All @@ -94,32 +102,35 @@ Logsene.prototype.log = function (level, msg, meta, callback) {
if (this.silent) {
return callback(null, true)
}
if (meta && (!meta['source'])) {
meta.source = this.source
if (this.setSource) {
if (meta && (!meta['source'])) {
meta.source = this.source
}
}
if (this.rewriter){
meta = this.rewriter(level, msg, meta)

if (this.rewriter) {
metaData = this.rewriter(level, msg, meta)
}
if (meta instanceof Error) {
if (!msg) {
msg = meta.stack || meta.message
}
metaData = {error_stack: meta.stack || meta.message}
msg = meta.stack || meta.message
}
metaData = {error_stack: meta.stack || meta.message}
}
var output = common.log({
colorize: this.colorize,
json: this.json,
level: level,
message: msg,
meta: metaData,
stringify: this.stringify,
timestamp: new Date(), //this.timestamp,
prettyPrint: this.prettyPrint,
raw: this.raw,
label: this.label
})
if (this.logsene_debug) {
console.log(output)
var output = common.log({
colorize: this.colorize,
json: this.json,
level: level,
message: msg,
meta: metaData,
stringify: this.stringify,
timestamp: new Date(), // this.timestamp,
prettyPrint: this.prettyPrint,
raw: this.raw,
label: this.label
})
console.log(output)
}
this.logger.log(level, msg, flat(metaData, this.flatOptions), callback)
}
Expand Down

0 comments on commit 51d7a04

Please sign in to comment.