3.0.1 • Published 11 months ago
@logtown/hono v3.0.1
Hono middleware for logging using logtown
Installation
npm install @logtown/hono
yarn add @logtown/hono
pnpm add @logtown/hono
bun add @logtown/honoUsage
import { SimpleConsoleWrapper } from "logtown";
import { loggerHttp } from "@logtown/hono";
import { Hono } from "hono";
import { getConnInfo } from "@hono/node-server/conninfo";
import { serve, type HttpBindings } from "@hono/node-server";
registerWrapper(SimpleConsoleWrapper);
const app = new Hono();
app.use(
"*",
loggerHttp({
format: process.env.NODE_ENV === "development" ? "short" : "apache-common",
getConnInfo,
transformers: {
"http-version": (context) => {
const bindings = (context.env.server ? context.env.server : context.env) as HttpBindings;
return bindings.incoming.httpVersion;
},
},
}),
);
serve({
fetch: app.fetch,
port: 3000,
});!NOTE
loggerHttpmiddleware does not colorize output, just a simple formatting according to the provided format. However, if you want to colorize the output, you can configure this within the Logtown Wrapper. TheloggerHttpprovides all the fields from the formatted string as an object.
License
@logtown/hono released under the Apache 2.0 license