diff --git a/src/main.js b/src/main.js index 6882434..e76bdd2 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,45 @@ import HMR from '@roxi/routify/hmr' import App from './App.svelte'; +import { logs } from './util/logs'; + +function display(formatted, type) { + const displayed = { + text: formatted, + type + }; + + logs.update(toDisplay => { + toDisplay.push(displayed); + return toDisplay; + }); + + if(type !== "error") { + setTimeout(() => { + logs.update(toDisplay => { + const i = toDisplay.indexOf(displayed); + toDisplay.splice(i, 1); + return toDisplay; + }); + }, 1000); + } +} + +const error = console.error.bind(console); +window.console.error = (...args) => { + error(...args); + display(JSON.stringify(args), "error"); +} + +window.onerror = (event, SourceBuffer, line, col, error) => { + error(error); + display(error.message + "\n" + error.stack, "error"); +} + +// const log = console.log.bind(console); +// window.console.log = (...args) => { +// log(...args); +// display(JSON.stringify(args), "log"); +//} const app = HMR(App, { target: document.body }, 'routify-app') diff --git a/src/pages/_layout.svelte b/src/pages/_layout.svelte index f1d582e..4925d51 100644 --- a/src/pages/_layout.svelte +++ b/src/pages/_layout.svelte @@ -1,2 +1,28 @@ + + + +{#if $logs.length} +
+ {#each $logs as item} +
+ {item.text} +
+ {/each} +
+{/if} + + \ No newline at end of file diff --git a/src/util/logs.js b/src/util/logs.js new file mode 100644 index 0000000..a542b7d --- /dev/null +++ b/src/util/logs.js @@ -0,0 +1,3 @@ +import { writable } from "svelte/store"; + +export const logs = writable([]); \ No newline at end of file