@voliware/logger
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -1,1 +0,1 @@ | ||
class Logger{constructor(e,t={}){return this.name=e,this.options={level:Logger.level.info,timestamp:{state:!1,format:Logger.timestamp.locale},context:null},Object.assign(this.options,t),this.setTimestampFormat(this.options.timestamp.format),this}setName(e){return this.name=e,this}setContext(e){return"string"==typeof e?this.options.context=e:"object"==typeof e&&(this.options.context=e.constructor.name),this}setLogLevel(e){return this.options.level=e,this}setTimestamp(e){return this.options.timestamp=e,this.setTimestampFormat(this.options.timestamp.format),this}setTimestampFormat(e){switch(e){case Logger.timestamp.utc:this.appendTimestamp=this.appendUtcTimestamp;break;case Logger.timestamp.localedate:this.appendTimestamp=this.appendLocaleDateTimestamp;break;case Logger.timestamp.localetime:this.appendTimestamp=this.appendLocaleTimeTimestamp;break;case Logger.timestamp.locale:default:this.appendTimestamp=this.appendLocaleTimestamp}return this}setCustomTimestampFormat(e){return this.appendTimestamp=e,this}appendUtcTimestamp(){return`[${(new Date).toUTCString()}] `}appendLocaleTimestamp(){return`[${(new Date).toLocaleString()}] `}appendLocaleTimeTimestamp(){return`[${(new Date).toLocaleTimeString()}] `}appendLocaleDateTimestamp(){return`[${(new Date).toLocaleDateString()}] `}createMessage(e,t){let s="";return this.options.timestamp.state&&(s+=this.appendTimestamp()),s+=`[${Logger.level.string[t]}] `,s+=`[${this.name}] `,this.options.context&&(s+=`[${this.options.context}] `),"string"==typeof e&&(s+=e),s}log(e,t=this.options.level){if(t<this.options.level)return!1;let s=this.createMessage(e,t);return"string"==typeof e?console.log(s):(console.log("logging object"),console.log(e)),!0}verbose(e){return this.log(e,Logger.level.verbose)}debug(e){return this.log(e,Logger.level.debug)}info(e){return this.log(e,Logger.level.info)}warning(e){return this.log(e,Logger.level.warning)}error(e){return this.log(e,Logger.level.error)}}Logger.level={verbose:0,debug:1,info:2,warning:3,error:4,string:["VRB","DBG","INF","WRN","ERR"]},Logger.timestamp={utc:0,locale:1,localetime:2,localedate:3},"undefined"!=typeof module&&(module.exports=Logger); | ||
class Logger{constructor(e,t={}){return this.name=e,this.options={level:Logger.level.info,timestamp:{state:!1,format:Logger.timestamp.locale},context:null},Object.assign(this.options,t),this.setContext(this.options.context),this.setTimestampFormat(this.options.timestamp.format),this}setName(e){return this.name=e,this}setContext(e){return"string"==typeof e?this.options.context=e:e&&e.constructor&&(this.options.context=e.constructor.name),this}setLogLevel(e){return this.options.level=e,this}setTimestamp(e){return this.options.timestamp=e,this.setTimestampFormat(this.options.timestamp.format),this}setTimestampFormat(e){switch(e){case Logger.timestamp.utc:this.appendTimestamp=this.appendUtcTimestamp;break;case Logger.timestamp.localedate:this.appendTimestamp=this.appendLocaleDateTimestamp;break;case Logger.timestamp.localetime:this.appendTimestamp=this.appendLocaleTimeTimestamp;break;case Logger.timestamp.locale:default:this.appendTimestamp=this.appendLocaleTimestamp}return this}setCustomTimestampFormat(e){return this.appendTimestamp=e,this}appendUtcTimestamp(){return`[${(new Date).toUTCString()}] `}appendLocaleTimestamp(){return`[${(new Date).toLocaleString()}] `}appendLocaleTimeTimestamp(){return`[${(new Date).toLocaleTimeString()}] `}appendLocaleDateTimestamp(){return`[${(new Date).toLocaleDateString()}] `}createMessage(e,t){let s="";return this.options.timestamp.state&&(s+=this.appendTimestamp()),s+=`[${Logger.level.string[t]}] `,s+=`[${this.name}] `,this.options.context&&(s+=`[${this.options.context}] `),"string"==typeof e&&(s+=e),s}log(e,t=this.options.level){if(t<this.options.level)return!1;let s=this.createMessage(e,t);return"string"==typeof e?console.log(s):(console.log("logging object"),console.log(e)),!0}verbose(e){return this.log(e,Logger.level.verbose)}debug(e){return this.log(e,Logger.level.debug)}info(e){return this.log(e,Logger.level.info)}warning(e){return this.log(e,Logger.level.warning)}error(e){return this.log(e,Logger.level.error)}}Logger.level={verbose:0,debug:1,info:2,warning:3,error:4,string:["VRB","DBG","INF","WRN","ERR"]},Logger.timestamp={utc:0,locale:1,localetime:2,localedate:3},"undefined"!=typeof module&&(module.exports=Logger); |
{ | ||
"name": "@voliware/logger", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "A tiny Javascript logger with levels and several options. Supports Node and all modern Browsers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -51,2 +51,3 @@ /** | ||
this.setContext(this.options.context); | ||
this.setTimestampFormat(this.options.timestamp.format); | ||
@@ -79,3 +80,3 @@ | ||
} | ||
else if(typeof context === 'object'){ | ||
else if(context && context.constructor){ | ||
this.options.context = context.constructor.name; | ||
@@ -82,0 +83,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
17253
380