Skip to content

Commit d88eded

Browse files
committed
feat: use context requestlog for server logs
1 parent 3371579 commit d88eded

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import { HTTPException } from "@hono/hono/http-exception";
33
import { logger } from "@hono/hono/logger";
44

55
import config from "./config.ts";
6-
import { contextMiddleware } from "./context.ts";
6+
import { contextMiddleware, getRequestLog } from "./context.ts";
77
import { hasKey, verify } from "./crypto.ts";
88
import handler from "./handler.ts";
99

1010
const app = new Hono();
1111

12-
app.use(logger());
1312
app.use(contextMiddleware);
1413

14+
// use context's requestlog for server logs
15+
app.use(logger((...args) => getRequestLog().log(...args)));
16+
1517
if (config.mainRedirect) {
1618
app.get("/", (c) => {
1719
return c.redirect(config.mainRedirect!);

src/util.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ export function wildcardMatch(pattern: string, target: string): boolean {
3232
* logging proxy that adds some metadata to log messages
3333
*/
3434
export function requestLog(deliveryId: string | undefined) {
35-
const prefix = deliveryId ? `[${deliveryId}] ` : "";
35+
const prefix = deliveryId ? `[${deliveryId}]` : "";
3636

3737
// ugh
3838
// is there a better way to do this? certainly.
3939
// does this work? also yes.
40-
const proxyLog: (func: (s: any) => void) => (msg: any) => void = (func) => {
41-
// FIXME: `String()` mangles objects
42-
return (msg) => func(prefix + String(msg));
40+
const proxyLog: (func: (...args: any[]) => void) => (...args: any[]) => void = (func) => {
41+
return (...args) => func(prefix, ...args);
4342
};
4443

4544
return {

0 commit comments

Comments
 (0)