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) => {