@mgcrea/hono-request-logger
v0.1.1
Published
<!-- markdownlint-disable MD033 --> <p align="center"> <a href="https://www.npmjs.com/package/@mgcrea/hono-request-logger"> <img src="https://img.shields.io/npm/v/@mgcrea/hono-request-logger.svg?style=for-the-badge" alt="npm version" /> </a> <a
Readme
Hono Request Logger
Features
A lightweight HTTP request logging middleware for Hono built on top of @logtape/logtape.
- Logs incoming requests and outgoing responses with method, path, status code, and latency.
- Color-coded status codes (2xx/3xx green, 4xx yellow, 5xx red) via picocolors.
- Automatically skips noisy
/metricsand/healthzendpoints. - Picks log level from response status:
debugfor 2xx/3xx,warnfor 4xx,errorfor 5xx. - Ships with an opinionated ANSI color formatter (
prettyFormatter) that understands logtaperequestIdcontext properties. - Unicode-aware — falls back to ASCII arrows on terminals that don't support UTF-8.
- Built with TypeScript for static type checking with exported types along the library.
Usage
npm install @mgcrea/hono-request-logger @logtape/logtape hono --save
# or
pnpm add @mgcrea/hono-request-logger @logtape/logtape honoBasic usage with Hono
import { Hono } from "hono";
import { configureLogger, httpLogger } from "@mgcrea/hono-request-logger";
await configureLogger();
const app = new Hono();
app.use("*", httpLogger());
app.get("/", (c) => c.text("Hello Hono!"));
export default app;Disabling incoming request logs
By default the middleware logs both the incoming request and the outgoing response. Pass logIncoming: false to only log responses:
app.use("*", httpLogger({ logIncoming: false }));Using the formatter with your own logtape configuration
If you already bootstrap logtape elsewhere, you can plug in the provided formatter directly:
import { configure, getConsoleSink } from "@logtape/logtape";
import { prettyFormatter } from "@mgcrea/hono-request-logger";
await configure({
sinks: { console: getConsoleSink({ formatter: prettyFormatter }) },
loggers: [{ category: [], sinks: ["console"], lowestLevel: "debug" }],
});Authors
License
The MIT License
Copyright (c) 2026 Olivier Louvignes <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.