feat: add logging setup for tauri desktop app (#397)

This commit is contained in:
Jonas Kruckenberg 2022-12-12 21:16:45 +01:00 committed by GitHub
parent d856abef9d
commit 85f619ea82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 3 deletions

21
composables/log.ts Normal file
View file

@ -0,0 +1,21 @@
import * as log from 'tauri-plugin-log-api'
// When running inside Tauri, catch all logs from 3rd party packages and direct them to the unified logging stream
export function setupLogging() {
if (import.meta.env.TAURI_PLATFORM) {
// eslint-disable-next-line no-global-assign
console = {
...console,
trace: log.trace,
debug: log.debug,
log: log.info,
warn: log.warn,
error: log.error,
}
window.addEventListener('unhandledrejection', err =>
log.error(err.reason),
)
window.addEventListener('error', err => log.error(err.error), true)
}
}