-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c750500
commit ca6d2e5
Showing
12 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import { goto } from "$lib/i18n"; | ||
let clicked:number = 0; | ||
const clicksNeeded = 5 | ||
const onClick = () => { | ||
clicked++; | ||
if (clicked === clicksNeeded) { | ||
clicked = 0; | ||
goto('/logs'); | ||
} | ||
} | ||
</script> | ||
<button on:click={onClick} class="absolute left-1/2 top-0 z-50 h-6 w-20"></button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { log } from '$lib/log'; | ||
import type { HandleClientError } from '@sveltejs/kit'; | ||
|
||
export const handleError: HandleClientError = async ({ error, event, status, message }) => { | ||
await log(String(error)) | ||
await log(JSON.stringify(event)) | ||
await log(JSON.stringify(status)); | ||
await log(message) | ||
|
||
return { | ||
message, | ||
status, | ||
event, | ||
error | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// import { dev } from '$app/environment'; | ||
import { setLogPreference } from './preferences/logs'; | ||
|
||
const dev = true; | ||
|
||
export const log = dev ? logAndSave : () => {}; | ||
|
||
async function logAndSave(message: string) { | ||
const stackTrace = new Error().stack; | ||
let callerInfo = ''; | ||
|
||
if (stackTrace) { | ||
const stackLines = stackTrace.split('\n'); | ||
for (let i = 2; i < stackLines.length; i++) { | ||
const match = stackLines[i].match(/at\s+(.*)\s+\((.*):(\d+):(\d+)\)/); | ||
if (match) { | ||
const functionName = match[1]; | ||
const fileName = match[2]?.replace(/^.*\/\/[^/]+/, ''); | ||
const lineNumber = match[3]; | ||
const columnNumber = match[4]; | ||
callerInfo = `${functionName} (${fileName}:${lineNumber}:${columnNumber})`; | ||
break; | ||
} | ||
} | ||
} | ||
const logMessage = callerInfo ? `${callerInfo}: ${message}` : message; | ||
console.log(logMessage); | ||
await setLogPreference(logMessage); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { getStructuredPreferences, setStructuredPreferences } from '.'; | ||
import dayjs from 'dayjs'; | ||
|
||
// | ||
|
||
export const LOGS_PREFERENCES_KEY = 'logs'; | ||
|
||
export type Log = { | ||
date: number; | ||
message: string; | ||
}; | ||
|
||
const getNow = async () => { | ||
return dayjs().valueOf(); | ||
}; | ||
|
||
export async function setLogPreference(message: string): Promise<Log> { | ||
const logs = await getLogsPreference(); | ||
const date = await getNow(); | ||
const c = { | ||
message, | ||
date | ||
}; | ||
if (logs) { | ||
logs.push(c); | ||
await setStructuredPreferences(LOGS_PREFERENCES_KEY, logs); | ||
return c; | ||
} | ||
|
||
await setStructuredPreferences(LOGS_PREFERENCES_KEY, [c]); | ||
return c; | ||
} | ||
|
||
export async function getLogsPreference(): Promise<Log[] | undefined> { | ||
return await getStructuredPreferences(LOGS_PREFERENCES_KEY); | ||
} | ||
|
||
export async function clearLogsPreferences(): Promise<void> { | ||
await setStructuredPreferences(LOGS_PREFERENCES_KEY, []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script lang="ts"> | ||
import { goto, r } from '$lib/i18n/index.js'; | ||
import dayjs from 'dayjs'; | ||
import { onMount } from 'svelte'; | ||
import { clearLogsPreferences } from '$lib/preferences/logs.js'; | ||
import { clearPreferences } from '$lib/preferences/index.js'; | ||
export let data; | ||
let element: HTMLElement; | ||
$: if (logs && element) scrollToBottom(element); | ||
onMount(() => { | ||
if (logs && element) scrollToBottom(element); | ||
}); | ||
const scrollToBottom = async (node: HTMLElement) => { | ||
node.scroll({ top: node.scrollHeight, behavior: 'smooth' }); | ||
}; | ||
const clear = async () => { | ||
await clearLogsPreferences(); | ||
window.location.reload() | ||
}; | ||
const { logs } = data; | ||
</script> | ||
|
||
<div class="ion-padding flex h-screen flex-col gap-4 overflow-auto" bind:this={element}> | ||
<div class="flex gap-2"> | ||
<d-button href={r('/home')}> back </d-button> | ||
<d-button on:click={clear}> clear </d-button> | ||
<d-button on:click={clearPreferences}> clear storage </d-button> | ||
</div> | ||
{#if logs} | ||
{#each logs as log} | ||
{@const date = dayjs(log.date)} | ||
<div class="flex gap-2 rounded-md border border-on bg-primary p-2"> | ||
<div class="flex flex-col"> | ||
<div class="text-sm text-on">{date.format('YY/MM/DD')}</div> | ||
<div class="text-sm text-on">{date.format('HH:mm:ss')}</div> | ||
</div> | ||
<div class="break-all text-sm text-on">{log.message}</div> | ||
</div> | ||
{/each} | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getLogsPreference } from '$lib/preferences/logs.js'; | ||
|
||
export const load = async () => { | ||
const logs = await getLogsPreference() || []; | ||
return { logs }; | ||
}; |