Skip to content

Commit

Permalink
chore: Export the RequestLogger interface. (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenikles authored Aug 24, 2023
1 parent 21777d4 commit 01ed8ec
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-bugs-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webstone-plugin-request-logger": patch
---

Export the RequestLogger Typescript interface.
5 changes: 4 additions & 1 deletion packages/plugin-request-logger/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
49 changes: 48 additions & 1 deletion packages/plugin-request-logger/src/lib/request-logger.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>): 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<string, unknown>): 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<string, unknown>): 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<string, unknown>): 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<string, unknown>): void;
}

export const addRequestLogger = (async ({ event, resolve }) => {
const request_id = randomUUID();

Expand All @@ -17,7 +64,7 @@ export const addRequestLogger = (async ({ event, resolve }) => {
return result;
}, {} as Console);

const logger = {
const logger: RequestLogger = {
...console,
...overwrites
};
Expand Down

0 comments on commit 01ed8ec

Please sign in to comment.