@voliware/logger
Advanced tools
Comparing version 1.5.3 to 1.6.0
{ | ||
"name": "@voliware/logger", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "A tiny Javascript logger with levels and several options. Supports Node and all modern Browsers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -184,2 +184,5 @@ /** | ||
break; | ||
case Logger.timestamp.numeric: | ||
this.appendTimestamp = this.appendNumericTimestamp | ||
break; | ||
case Logger.timestamp.locale: | ||
@@ -240,6 +243,15 @@ default: | ||
/** | ||
* Append a numerical timestamp. | ||
* eg 1628828513146 | ||
* @return {Logger} | ||
*/ | ||
appendNumericTimestamp(){ | ||
return `[${Date.now()}] `; | ||
} | ||
/** | ||
* Create a log message. | ||
* @param {String} message - message to log | ||
* @param {Number} level - log level | ||
* @return {Logger} | ||
* @return {String} | ||
*/ | ||
@@ -400,3 +412,4 @@ createMessage(message, level){ | ||
localetime: 2, | ||
localedate: 3 | ||
localedate: 3, | ||
numeric | ||
}; | ||
@@ -412,3 +425,4 @@ | ||
.set("localetime", Logger.timestamp.localetime) | ||
.set("localedate", Logger.timestamp.localedate); | ||
.set("localedate", Logger.timestamp.localedate) | ||
.set("numeric", Logger.timestamp.numeric); | ||
@@ -421,3 +435,3 @@ /** | ||
Logger.timestamp.isValidTimestamp = function(timestamp){ | ||
return timestamp >= Logger.timestamp.utc && timestamp <= Logger.timestamp.localedate; | ||
return timestamp >= Logger.timestamp.utc && timestamp <= Logger.timestamp.numeric; | ||
}; | ||
@@ -424,0 +438,0 @@ |
@@ -32,2 +32,3 @@ const Logger = require('./logger'); | ||
* @param {String} [options.output.file=""] - a file to save the log to, or blank for none | ||
* @param {Collection} [options.output.mongodb=null] - a reference to a MongoDB collection | ||
* @return {Logger} | ||
@@ -39,3 +40,4 @@ */ | ||
console: true, | ||
file: "" | ||
file: "", | ||
mongodb: null | ||
} | ||
@@ -48,2 +50,3 @@ }; | ||
this.fileIsValid = this.isValidFilepath(this.options.output.file); | ||
this.mongodb = defaults.mongodb; | ||
return this; | ||
@@ -163,4 +166,29 @@ } | ||
} | ||
/** | ||
* Create a log message. | ||
* Override to insert into mongodb if set. | ||
* @param {String} message - message to log | ||
* @param {Number} level - log level | ||
* @return {String} | ||
*/ | ||
createMessage(message, level){ | ||
if(this.mongodb){ | ||
const doc = { | ||
level: Logger.level.string[level], | ||
message: message, | ||
name: this.name | ||
}; | ||
if(this.options.timestamp.state){ | ||
doc.time = this.appendTimestamp(); | ||
} | ||
if(this.options.context){ | ||
doc.context = this.options.context; | ||
} | ||
this.mongodb.insertOne(doc); | ||
} | ||
return super.createMessage(message, level); | ||
} | ||
} | ||
module.exports = NodeLogger; |
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
30258
744