Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 985 Bytes
19c8b95 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
"use strict"
const fs = require("fs")
class xVAAppLogger {
constructor (fileLocation, appVersion) {
this.lines = []
this.fileLocation = fileLocation
if (fs.existsSync(fileLocation)) {
const data = fs.readFileSync(fileLocation, "utf8")
this.lines = data.split("\n")
}
this.prefix = ""
this.log(`New session - ${appVersion}`)
}
log (message) {
this.lines.push(`${(new Date()).toJSON().replace("T", "_")} |${this.prefix.length?` [${this.prefix}]:`:""} ${message}`)
if (this.lines.length>1000) {
this.lines = this.lines.slice(this.lines.length-1000, this.lines.length)
}
fs.writeFileSync(this.fileLocation, this.lines.join("\n"), "utf8")
}
print (message) {
console.log(`${this.prefix.length?` [${this.prefix}]:`:""} ${message}`)
}
setPrefix (prefix) {
this.prefix = prefix
}
}
exports.xVAAppLogger = xVAAppLogger
|