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

main
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

View File

@ -1,4 +1,5 @@
<script setup lang="ts">
setupLogging()
setupPageHeader()
await setupI18n()
provideGlobalCommands()

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)
}
}

View File

@ -32,6 +32,10 @@ export default defineNuxtConfig({
querystring: 'rollup-plugin-node-polyfills/polyfills/qs',
},
vite: {
// to make use of `TAURI_PLATFORM`, `TAURI_ARCH`, `TAURI_FAMILY`,
// `TAURI_PLATFORM_VERSION`, `TAURI_PLATFORM_TYPE` and `TAURI_DEBUG`
// env variables
envPrefix: ['VITE_', 'TAURI_'],
define: {
'import.meta.env.__BUILD_TIME__': JSON.stringify(new Date().toISOString()),
'import.meta.env.__BUILD_COMMIT__': JSON.stringify(process.env.COMMIT_REF || ''),
@ -39,7 +43,7 @@ export default defineNuxtConfig({
'process.mock': ((!isCI || isPreview) && process.env.MOCK_USER) || 'false',
},
build: {
target: 'esnext',
target: process.env.TAURI_PLATFORM ? ['es2021', 'chrome100', 'safari13'] : 'esnext',
},
plugins: [
Inspect(),

View File

@ -18,7 +18,8 @@
"postinstall": "nuxi prepare && simple-git-hooks"
},
"dependencies": {
"@fnando/sparkline": "^0.3.10"
"@fnando/sparkline": "^0.3.10",
"tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log"
},
"devDependencies": {
"@antfu/eslint-config": "^0.33.1",

View File

@ -56,6 +56,7 @@ specifiers:
shiki-es: ^0.1.2
simple-git-hooks: ^2.8.1
std-env: ^3.3.1
tauri-plugin-log-api: github:tauri-apps/tauri-plugin-log
theme-vitesse: ^0.6.0
tippy.js: ^6.3.7
typescript: ^4.9.3
@ -70,6 +71,7 @@ specifiers:
dependencies:
'@fnando/sparkline': 0.3.10
tauri-plugin-log-api: github.com/tauri-apps/tauri-plugin-log/b58475bbc410fa78eb69276c62d0b64c91c07914
devDependencies:
'@antfu/eslint-config': 0.33.1_s5ps7njkmjlaqajutnox5ntcla
@ -1314,6 +1316,11 @@ packages:
rollup: 2.79.1
dev: true
/@tauri-apps/api/1.2.0:
resolution: {integrity: sha512-lsI54KI6HGf7VImuf/T9pnoejfgkNoXveP14pVV7XarrQ46rOejIVJLFqHI9sRReJMGdh2YuCoI3cc/yCWCsrw==}
engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'}
dev: false
/@tiptap/core/2.0.0-beta.204:
resolution: {integrity: sha512-MH4LQE6rvX+DAy83tZH5E6gaA/hO5A6F/w5ZM6En5PcRhNsgpfQl+kjRfeVQYahxouc1mzetayhRe4XQ8PAwng==}
dependencies:
@ -8008,7 +8015,6 @@ packages:
/tslib/2.4.1:
resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==}
dev: true
/tsutils/3.21.0_typescript@4.9.3:
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
@ -9020,3 +9026,12 @@ packages:
compress-commons: 4.1.1
readable-stream: 3.6.0
dev: true
github.com/tauri-apps/tauri-plugin-log/b58475bbc410fa78eb69276c62d0b64c91c07914:
resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-log/tar.gz/b58475bbc410fa78eb69276c62d0b64c91c07914}
name: tauri-plugin-log-api
version: 0.1.0
dependencies:
'@tauri-apps/api': 1.2.0
tslib: 2.4.1
dev: false