From 1576d92efccc82b3d623190f522e7c0a3dc066b9 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 30 Jan 2026 21:54:44 -0800 Subject: [PATCH] logging: false --- src/index.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index ea2305b..ab87f82 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -24,6 +24,7 @@ export type HypeProps = { reset?: boolean prettyHTML?: boolean layout?: boolean + logging?: boolean } type InternalProps = HypeProps & { _isRouter?: boolean } @@ -89,16 +90,18 @@ export class Hype< this.use('/css/*', serveStatic({ root: './src' })) // console logging - this.use('*', async (c, next) => { - if (!SHOW_HTTP_LOG) return await next() + if (this.props.logging !== false) { + this.use('*', async (c, next) => { + if (!SHOW_HTTP_LOG) return await next() - const start = Date.now() - await next() - const end = Date.now() - const fn = c.res.status < 400 ? color.green : c.res.status < 500 ? color.yellow : color.red - const method = c.req.method === 'GET' ? color.cyan(c.req.method) : color.magenta(c.req.method) - console.log(fn(`${c.res.status}`), `${color.bold(method)} ${c.req.url} (${end - start}ms)`) - }) + const start = Date.now() + await next() + const end = Date.now() + const fn = c.res.status < 400 ? color.green : c.res.status < 500 ? color.yellow : color.red + const method = c.req.method === 'GET' ? color.cyan(c.req.method) : color.magenta(c.req.method) + console.log(fn(`${c.res.status}`), `${color.bold(method)} ${c.req.url} (${end - start}ms)`) + }) + } // exception handler this.onError((err, c) => {