@voliware/logger
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -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.extend(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"string"==typeof e&&(e=Logger.level.stringmap.get(e)),Logger.level.isValidLevel(e)?(this.options.level=e,this):(console.error("Logger.setLogLevel: invalid log level"),this)}setTimestamp(e){return Object.extend(this.options.timestamp,e),this.setTimestampFormat(this.options.timestamp.format),this}setTimestampState(e){return this.options.timestamp.state=e,this}setTimestampFormat(e){if("string"==typeof e&&(e=Logger.timestamp.stringmap.get(e)),!Logger.timestamp.isValidTimestamp(e))return console.error("Logger.setTimestampFormat: invalid timestamp"),this;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 o="";return this.options.timestamp.state&&(o+=this.appendTimestamp()),o+=`[${Logger.level.string[t]}] `,o+=`[${this.name}] `,this.options.context&&(o+=`[${this.options.context}] `),"string"==typeof e&&(o+=e),o}log(e,t=this.options.level){if(t<this.options.level)return!1;let o=this.createMessage(e,t);return"string"==typeof e?console.log(o):(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.level.stringmap=(new Map).set("verbose",Logger.level.verbose).set("debug",Logger.level.debug).set("info",Logger.level.info).set("warning",Logger.level.warning).set("error",Logger.level.error),Logger.level.isValidLevel=function(e){return e>=Logger.level.verbose&&e<=Logger.level.error},Logger.timestamp={utc:0,locale:1,localetime:2,localedate:3},Logger.timestamp.stringmap=(new Map).set("utc",Logger.timestamp.utc).set("locale",Logger.timestamp.locale).set("localetime",Logger.timestamp.localetime).set("localedate",Logger.timestamp.localedate),Logger.timestamp.isValidTimestamp=function(e){return e>=Logger.timestamp.utc&&e<=Logger.timestamp.localedate},"function"!=typeof Object.extend&&(Object.extend=function(){for(let e=1;e<arguments.length;e++)for(let t in arguments[e])if(arguments[e].hasOwnProperty(t)){if(!arguments[0])continue;"object"==typeof arguments[0][t]&&"object"==typeof arguments[e][t]?Object.extend(arguments[0][t],arguments[e][t]):arguments[0][t]=arguments[e][t]}return arguments[0]}),"undefined"!=typeof module&&(module.exports=Logger); | ||
class Logger{constructor(e,t={}){return this.name=e,this.options={level:Logger.level.info,context:null,timestamp:{state:!1,format:Logger.timestamp.locale}},Object.extend(this.options,t),this.setContext(this.options.context),this.setTimestamp(this.options.timestamp),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"string"==typeof e&&(e=Logger.level.stringmap.get(e)),Logger.level.isValidLevel(e)?(this.options.level=e,this):(console.error("Logger.setLogLevel: invalid log level"),this)}setTimestamp(e){return"boolean"==typeof e&&(this.options.timestamp={state:e,format:Logger.timestamp.locale}),this.setTimestampState(this.options.timestamp.state),this.setTimestampFormat(this.options.timestamp.format),this}setTimestampState(e){return this.options.timestamp.state=e,this}setTimestampFormat(e){if("string"==typeof e&&(e=Logger.timestamp.stringmap.get(e)),!Logger.timestamp.isValidTimestamp(e))return console.error("Logger.setTimestampFormat: invalid timestamp"),this;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 o="";return this.options.timestamp.state&&(o+=this.appendTimestamp()),o+=`[${Logger.level.string[t]}] `,o+=`[${this.name}] `,this.options.context&&(o+=`[${this.options.context}] `),"string"==typeof e&&(o+=e),o}log(e,t=this.options.level){if(t<this.options.level)return this;let o=this.createMessage(e,t);return this.logMessage(o)}logMessage(e){return"string"==typeof e?console.log(e):(console.log("logging object"),console.log(e)),this}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.level.stringmap=(new Map).set("verbose",Logger.level.verbose).set("debug",Logger.level.debug).set("info",Logger.level.info).set("warning",Logger.level.warning).set("error",Logger.level.error),Logger.level.isValidLevel=function(e){return e>=Logger.level.verbose&&e<=Logger.level.error},Logger.timestamp={utc:0,locale:1,localetime:2,localedate:3},Logger.timestamp.stringmap=(new Map).set("utc",Logger.timestamp.utc).set("locale",Logger.timestamp.locale).set("localetime",Logger.timestamp.localetime).set("localedate",Logger.timestamp.localedate),Logger.timestamp.isValidTimestamp=function(e){return e>=Logger.timestamp.utc&&e<=Logger.timestamp.localedate},"function"!=typeof Object.extend&&(Object.extend=function(){for(let e=1;e<arguments.length;e++)for(let t in arguments[e])if(arguments[e].hasOwnProperty(t)){if(!arguments[0])continue;"object"==typeof arguments[0][t]&&"object"==typeof arguments[e][t]?Object.extend(arguments[0][t],arguments[e][t]):arguments[0][t]=arguments[e][t]}return arguments[0]}),"undefined"!=typeof module&&(module.exports=Logger); |
{ | ||
"name": "@voliware/logger", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A tiny Javascript logger with levels and several options. Supports Node and all modern Browsers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
27542