feat(ui): add structured JSON logging to all server-side routes and lib
Introduces a logger.ts module emitting slog-compatible JSON lines to stderr. Replaces silent catch blocks and console.error calls throughout minio.ts, pocketbase.ts, hooks.server.ts, login, books, browse, and all API routes so auth/registration failures, MinIO presign errors, and scraper proxy failures are now visible in container logs.
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { listBooks, allProgress } from '$lib/server/pocketbase';
|
||||
import { log } from '$lib/server/logger';
|
||||
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
const [books, progressList] = await Promise.all([
|
||||
listBooks(),
|
||||
allProgress(locals.sessionId)
|
||||
]);
|
||||
let books: Awaited<ReturnType<typeof listBooks>>;
|
||||
let progressList: Awaited<ReturnType<typeof allProgress>>;
|
||||
|
||||
try {
|
||||
[books, progressList] = await Promise.all([
|
||||
listBooks(),
|
||||
allProgress(locals.sessionId)
|
||||
]);
|
||||
} catch (e) {
|
||||
log.error('books', 'failed to load books or progress', { err: String(e) });
|
||||
books = [];
|
||||
progressList = [];
|
||||
}
|
||||
|
||||
// Build a quick lookup: slug → last chapter read
|
||||
const progressMap: Record<string, number> = {};
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getBook, listChapterIdx, getProgress } from '$lib/server/pocketbase';
|
||||
import { log } from '$lib/server/logger';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
const { slug } = params;
|
||||
|
||||
const [book, chapters, progress] = await Promise.all([
|
||||
getBook(slug),
|
||||
listChapterIdx(slug),
|
||||
getProgress(locals.sessionId, slug)
|
||||
]);
|
||||
let book: Awaited<ReturnType<typeof getBook>>;
|
||||
let chapters: Awaited<ReturnType<typeof listChapterIdx>>;
|
||||
let progress: Awaited<ReturnType<typeof getProgress>>;
|
||||
|
||||
try {
|
||||
[book, chapters, progress] = await Promise.all([
|
||||
getBook(slug),
|
||||
listChapterIdx(slug),
|
||||
getProgress(locals.sessionId, slug)
|
||||
]);
|
||||
} catch (e) {
|
||||
log.error('books', 'failed to load book page', { slug, err: String(e) });
|
||||
throw error(500, 'Failed to load book');
|
||||
}
|
||||
|
||||
if (!book) {
|
||||
log.warn('books', 'book not found', { slug });
|
||||
error(404, `Book "${slug}" not found`);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { marked } from 'marked';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getBook, listChapterIdx } from '$lib/server/pocketbase';
|
||||
import { presignChapter } from '$lib/server/minio';
|
||||
import { log } from '$lib/server/logger';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
const { slug } = params;
|
||||
@@ -28,7 +29,7 @@ export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
html = await marked(markdown, { async: true });
|
||||
} catch (e) {
|
||||
// Don't hard-fail — show empty content with error message
|
||||
console.error('Failed to fetch chapter content:', e);
|
||||
log.error('chapter', 'failed to fetch chapter content', { slug, n, err: String(e) });
|
||||
}
|
||||
|
||||
const prevChapter = chapters.find((c) => c.number === n - 1) ?? null;
|
||||
|
||||
Reference in New Issue
Block a user