mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-03 09:34:51 +02:00
Add AbsLogger plugin, persist logs to db, logs page for android
This commit is contained in:
parent
b9e3ccd0c1
commit
390388fe83
10 changed files with 208 additions and 10 deletions
42
plugins/capacitor/AbsLogger.js
Normal file
42
plugins/capacitor/AbsLogger.js
Normal file
|
@ -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 }
|
Loading…
Add table
Add a link
Reference in a new issue