wifi-tally_Oostendam/wifi-tally/hub/domain/Log.js
Eljakim Herrewijnen 50b5fc1824 Initial commit
2021-09-27 21:52:27 +02:00

53 lines
1.2 KiB
JavaScript

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;