mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-25 21:04:02 +02:00
Add AbsLogger plugin, persist logs to db, logs page for android
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { registerPlugin, WebPlugin } from '@capacitor/core'
|
||||
|
||||
class AbsLoggerWeb extends WebPlugin {
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
this.logs = []
|
||||
}
|
||||
|
||||
saveLog(level, message) {
|
||||
this.logs.push({
|
||||
id: Math.random().toString(36).substring(2, 15),
|
||||
timestamp: Date.now(),
|
||||
level: level,
|
||||
message: message
|
||||
})
|
||||
}
|
||||
|
||||
async info(data) {
|
||||
if (data?.message) {
|
||||
this.saveLog('info', data.message)
|
||||
console.log('AbsLogger: info', data.message)
|
||||
}
|
||||
}
|
||||
|
||||
async error(data) {
|
||||
if (data?.message) {
|
||||
this.saveLog('error', data.message)
|
||||
console.error('AbsLogger: error', data.message)
|
||||
}
|
||||
}
|
||||
|
||||
async getAllLogs() {
|
||||
return this.logs
|
||||
}
|
||||
}
|
||||
|
||||
const AbsLogger = registerPlugin('AbsLogger', {
|
||||
web: () => new AbsLoggerWeb()
|
||||
})
|
||||
|
||||
export { AbsLogger }
|
||||
Reference in New Issue
Block a user