|
|
|
|
|
|
|
|
|
|
|
|
|
|
const debug = require('debug'); |
|
|
const debug = require('debug'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ENABLE_STATE_LOG = true; |
|
|
|
|
|
var ENABLE_STATE_INFO = true; |
|
|
var ENABLE_STATE_INFO = true; |
|
|
var ENABLE_STATE_DEBUG = true; |
|
|
var ENABLE_STATE_DEBUG = true; |
|
|
var ENABLE_STATE_WARNING = true; |
|
|
var ENABLE_STATE_WARNING = true; |
|
|
|
|
|
|
|
|
constructor(namespace){ |
|
|
constructor(namespace){ |
|
|
this.__ns = namespace; |
|
|
this.__ns = namespace; |
|
|
this.__d = debug(namespace); |
|
|
this.__d = debug(namespace); |
|
|
this.__d.enabled = ENABLE_STATE_LOG; |
|
|
|
|
|
|
|
|
//console.log(debug); |
|
|
this.__fnc = null; |
|
|
this.__fnc = null; |
|
|
this.__enabled = ENABLE_STATE_LOG; |
|
|
|
|
|
this.__ienabled = ENABLE_STATE_INFO; |
|
|
this.__ienabled = ENABLE_STATE_INFO; |
|
|
this.__denabled = ENABLE_STATE_DEBUG; |
|
|
this.__denabled = ENABLE_STATE_DEBUG; |
|
|
this.__wenabled = ENABLE_STATE_WARNING; |
|
|
this.__wenabled = ENABLE_STATE_WARNING; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get namespace(){return this.__ns;} |
|
|
get namespace(){return this.__ns;} |
|
|
|
|
|
|
|
|
get enabled(){return this.__enabled;} |
|
|
|
|
|
set enabled(e){this.__enabled = (e === true);} |
|
|
|
|
|
|
|
|
get enabled(){return this.__d.enabled} |
|
|
|
|
|
set enabled(e){ |
|
|
|
|
|
this.__d.enabled = (e === true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
get infoEnabled(){return this.__ienabled;} |
|
|
get infoEnabled(){return this.__ienabled;} |
|
|
set infoEnabled(e){this.__ienabled = (e === true);} |
|
|
set infoEnabled(e){this.__ienabled = (e === true);} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log(){ |
|
|
log(){ |
|
|
if (!ENABLE_STATE_LOG || !this.__enabled || arguments.length < 2){return;} |
|
|
|
|
|
|
|
|
if (!this.__d.enabled || arguments.length < 2){return;} |
|
|
var type = arguments[0]; |
|
|
var type = arguments[0]; |
|
|
var args = Array.prototype.slice.call(arguments, 1); |
|
|
var args = Array.prototype.slice.call(arguments, 1); |
|
|
if (typeof(args[0]) !== 'string'){return;} |
|
|
if (typeof(args[0]) !== 'string'){return;} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
info(){ |
|
|
info(){ |
|
|
let args = Array.prototype.slice.call(arguments); |
|
|
|
|
|
args.splice(0, 0, 'i'); |
|
|
|
|
|
this.log.apply(this, args); |
|
|
|
|
|
|
|
|
this.log.apply(this, ['i'].concat(Array.prototype.slice.call(arguments))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
debug(){ |
|
|
debug(){ |
|
|
let args = (Array.prototype.slice(arguments)).splice(0, 0, 'd'); |
|
|
|
|
|
this.log.apply(this, args); |
|
|
|
|
|
|
|
|
this.log.apply(this, ['d'].concat(Array.prototype.slice.call(arguments))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
warning(){ |
|
|
warning(){ |
|
|
let args = (Array.prototype.slice(arguments)).splice(0, 0, 'w'); |
|
|
|
|
|
this.log.apply(this, args); |
|
|
|
|
|
|
|
|
this.log.apply(this, ['w'].concat(Array.prototype.slice.call(arguments))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
error(){ |
|
|
error(){ |
|
|
let args = (Array.prototype.slice(arguments)).splice(0, 0, 'e'); |
|
|
|
|
|
this.log.apply(this, args); |
|
|
|
|
|
|
|
|
this.log.apply(this, ['e'].concat(Array.prototype.slice.call(arguments))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
critical(){ |
|
|
critical(){ |
|
|
let args = (Array.prototype.slice(arguments)).splice(0, 0, 'c'); |
|
|
|
|
|
this.log.apply(this, args); |
|
|
|
|
|
|
|
|
this.log.apply(this, ['c'].concat(Array.prototype.slice.call(arguments))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
extend(ens){ |
|
|
extend(ens){ |
|
|
var nlog = new LOG(this.__ns + ":" + ens); |
|
|
var nlog = new LOG(this.__ns + ":" + ens); |
|
|
nlog.enabled = this.__enabled; |
|
|
|
|
|
|
|
|
nlog.enabled = this.__d.enable; |
|
|
nlog.infoEnabled = this.__ienabled; |
|
|
nlog.infoEnabled = this.__ienabled; |
|
|
nlog.debugEnabled = this.__denabled; |
|
|
nlog.debugEnabled = this.__denabled; |
|
|
nlog.warningEnabled = this.__wenabled; |
|
|
nlog.warningEnabled = this.__wenabled; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
module.exports = { |
|
|
Log:Log, |
|
|
Log:Log, |
|
|
enabled: function(){ |
|
|
|
|
|
if (arguments.length > 0) |
|
|
|
|
|
ENABLE_STATE_LOG = (arguments[0] === true); |
|
|
|
|
|
return ENABLE_STATE_LOG; |
|
|
|
|
|
|
|
|
enable: function(namespace){ |
|
|
|
|
|
let l = LOG_LIST.find((lg)=>{return lg.namespace === namespace;}); |
|
|
|
|
|
if (l) |
|
|
|
|
|
l.enabled = true; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
enabled: function(namespace){ |
|
|
|
|
|
let l = LOG_LIST.find((lg)=>{return lg.namespace === namespace;}); |
|
|
|
|
|
return (l) ? l.enabled : false; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
disable: function(){ |
|
|
|
|
|
LOG_LIST.forEach((l)=>{l.enabled=false;}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
infoEnabled: function(){ |
|
|
infoEnabled: function(){ |