Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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