1
0
mirror of https://github.com/advplyr/audiobookshelf.git synced 2025-03-14 00:21:31 +01:00
audiobookshelf/server/scanner/ScanLogger.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-03-08 20:46:36 +01:00
const uuidv4 = require('uuid').v4
2023-09-04 00:51:58 +02:00
const Logger = require('../Logger')
class ScanLogger {
constructor() {
this.id = null
this.type = null
this.name = null
this.verbose = false
this.startedAt = null
this.finishedAt = null
this.elapsed = null
/** @type {string[]} */
this.authorsRemovedFromBooks = []
/** @type {string[]} */
this.seriesRemovedFromBooks = []
this.logs = []
}
toJSON() {
return {
id: this.id,
type: this.type,
name: this.name,
startedAt: this.startedAt,
finishedAt: this.finishedAt,
elapsed: this.elapsed
}
}
setData(type, name) {
this.id = uuidv4()
this.type = type
this.name = name
this.startedAt = Date.now()
}
setComplete() {
this.finishedAt = Date.now()
this.elapsed = this.finishedAt - this.startedAt
}
addLog(level, ...args) {
const logObj = {
2025-03-08 20:46:36 +01:00
timestamp: new Date().toISOString(),
2023-09-04 00:51:58 +02:00
message: args.join(' '),
2025-03-08 20:46:36 +01:00
levelName: Logger.getLogLevelString(level),
2023-09-04 00:51:58 +02:00
level
}
if (this.verbose) {
Logger.debug(`[Scan] "${this.name}":`, ...args)
}
this.logs.push(logObj)
}
}
2025-03-08 20:46:36 +01:00
module.exports = ScanLogger