Guides / Platforms & Tools
bun add logit hono
// lib/logit.ts
import { init } from "logit";
export const logit = init({ token: process.env.LOGIT_API_KEY! });
// index.ts
import { Hono } from "hono";
import { logit } from "./lib/logit";
const app = new Hono();
app.post("/checkout", async (c) => {
const body = await c.req.json<{ email: string; plan: string }>();
await logit.now("payments", {
event: "Checkout started",
description: `${body.email} โ plan: ${body.plan}`,
icon: "๐ณ",
notify: true,
tags: { plan: body.plan },
metadata: { email: body.email, plan: body.plan },
});
return c.json({ ok: true });
});
app.onError(async (err, c) => {
await logit.now("errors", {
event: "Hono error",
description: err.message,
icon: "โ",
notify: true,
metadata: { path: c.req.path, method: c.req.method },
});
return c.json({ error: "Internal error" }, 500);
});
export default {
port: 3000,
fetch: app.fetch,
};
import type { MiddlewareHandler } from "hono";
export const responseTime: MiddlewareHandler = async (c, next) => {
const start = Date.now();
await next();
const duration = Date.now() - start;
c.header("X-Response-Time", `${duration}ms`);
if (duration > 2000) {
await logit.now("perf", {
event: "Slow Hono response",
description: `${c.req.method} ${c.req.path} โ ${duration}ms`,
icon: "๐ข",
notify: false,
metadata: { path: c.req.path, durationMs: duration },
});
}
};
app.use("*", responseTime);
// Using Bun.cron (Bun v1.1+)
Bun.cron("0 * * * *", async () => {
await logit.now("cron", {
event: "Hourly job started",
description: "Running scheduled cleanup",
icon: "โฐ",
notify: false,
metadata: { runtime: "bun", version: Bun.version },
});
await runCleanup();
});
Try LogIt free
7-day trial. No credit card required.