3.0.1 • Published 11 months ago

@logtown/hono v3.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

Hono middleware for logging using logtown

npm

Installation

npm install @logtown/hono
yarn add @logtown/hono
pnpm add @logtown/hono
bun add @logtown/hono

Usage

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 loggerHttp middleware 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. The loggerHttp provides all the fields from the formatted string as an object.

License

@logtown/hono released under the Apache 2.0 license

Donate

npm.io npm.io

3.0.1

11 months ago

3.0.0

11 months ago