wifi-tally_Oostendam/wifi-tally/hub/domain/Log.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-09-27 19:52:27 +00:00
class Log {
constructor(dateTime, severity, message) {
if(typeof dateTime === "string") {
dateTime = new Date(dateTime)
} else if (typeof dateTime !== "object") {
dateTime = new Date()
}
this.dateTime = dateTime
if (severity === "INFO") {
severity = Log.INFO
} else if (severity === "ERROR") {
severity = Log.ERROR
} else if (severity === "WARN") {
severity = Log.WARNING
}
this.severity = severity
this.message = message
}
isError() {
return this.severity === Log.ERROR
}
isWarning() {
return this.severity === Log.WARNING
}
isInfo() {
return this.severity === Log.INFO
}
isStatus() {
return this.severity === Log.STATUS
}
toValueObject() {
return {
date: this.dateTime.toISOString(),
severity: this.severity,
message: this.message
}
}
}
Log.fromValueObject = function(valueObject) {
return new Log(
valueObject.date,
valueObject.severity,
valueObject.message
)
}
Log.INFO = 0
Log.WARNING = 1
Log.ERROR = 2
Log.STATUS = 3
module.exports = Log;