diff --git a/.changeset/empty-bugs-move.md b/.changeset/empty-bugs-move.md new file mode 100644 index 00000000..c894b7c7 --- /dev/null +++ b/.changeset/empty-bugs-move.md @@ -0,0 +1,5 @@ +--- +"webstone-plugin-request-logger": patch +--- + +Export the RequestLogger Typescript interface. diff --git a/packages/plugin-request-logger/src/app.d.ts b/packages/plugin-request-logger/src/app.d.ts index e57c6630..3aa3b7da 100644 --- a/packages/plugin-request-logger/src/app.d.ts +++ b/packages/plugin-request-logger/src/app.d.ts @@ -1,10 +1,13 @@ // See https://kit.svelte.dev/docs/types#app + +import type { RequestLogger } from '$lib/request-logger.ts'; + // for information about these interfaces declare global { namespace App { // interface Error {} interface Locals { - logger: Console; + logger: RequestLogger; } // interface PageData {} // interface Platform {} diff --git a/packages/plugin-request-logger/src/lib/request-logger.ts b/packages/plugin-request-logger/src/lib/request-logger.ts index 4df9c8ee..1b8f8368 100644 --- a/packages/plugin-request-logger/src/lib/request-logger.ts +++ b/packages/plugin-request-logger/src/lib/request-logger.ts @@ -1,6 +1,53 @@ import type { Handle } from '@sveltejs/kit'; import { randomUUID } from 'node:crypto'; +export interface RequestLogger extends Console { + /** + * Overrides the Console's debug function. + * Logs a debug message with optional additional data. + * + * @param message - The debug message to log. + * @param log_data - Optional additional data to include in the log. + */ + debug(message: string, log_data?: Record): void; + + /** + * Overrides the Console's error function. + * Logs an error message with optional additional data. + * + * @param message - The error message to log. + * @param log_data - Optional additional data to include in the log. + */ + error(message: string, log_data?: Record): void; + + /** + * Overrides the Console's info function. + * Logs an info message with optional additional data. + * + * @param message - The info message to log. + * @param log_data - Optional additional data to include in the log. + */ + info(message: string, log_data?: Record): void; + + /** + * Overrides the Console's log function. + * Logs a log message with optional additional data. + * + * @param message - The log message to log. + * @param log_data - Optional additional data to include in the log. + */ + log(message: string, log_data?: Record): void; + + /** + * Overrides the Console's warn function. + * Logs a warning message with optional additional data. + * + * @param message - The warning message to log. + * @param log_data - Optional additional data to include in the log. + */ + warn(message: string, log_data?: Record): void; +} + export const addRequestLogger = (async ({ event, resolve }) => { const request_id = randomUUID(); @@ -17,7 +64,7 @@ export const addRequestLogger = (async ({ event, resolve }) => { return result; }, {} as Console); - const logger = { + const logger: RequestLogger = { ...console, ...overwrites };