Bun / Node.js
Add logging to Bun or Node.js apps
Bun / Node.js
Section titled “Bun / Node.js”npm install github:karloscodes/lognorth-sdk-tsQuick Start
Section titled “Quick Start”import LogNorth from '@karloscodes/lognorth-sdk'
LogNorth.config('https://logs.yoursite.com', 'your-api-key')
LogNorth.log('User signed up', { user_id: 123 })LogNorth.error('Checkout failed', err, { order_id: 42 })Middleware
Section titled “Middleware”// Expressimport { middleware } from '@karloscodes/lognorth-sdk/express'app.use(middleware())
// Honoimport { middleware } from '@karloscodes/lognorth-sdk/hono'app.use(middleware())
// Next.jsimport { withLogger } from '@karloscodes/lognorth-sdk/next'export const GET = withLogger()(handler)The middleware automatically:
- Generates a
trace_idper request (or usesX-Trace-IDfrom the incoming header) - Sets
X-Trace-IDon the response - Logs the request with
duration_msandtrace_idas top-level fields - All
LogNorth.log()andLogNorth.error()calls within the request automatically inherit the sametrace_id
app.use(middleware())
app.post('/users', (req, res) => { // This log automatically gets the same trace_id as the middleware request log LogNorth.log('User signed up', { user_id: 123 }) res.status(201).json({ ok: true })})Ignoring Routes
Section titled “Ignoring Routes”Skip health checks and other noisy endpoints:
app.use(middleware({ ignorePaths: ['/healthz', '/_health', '/metrics']}))These paths won’t be logged by the middleware.
With Pino
Section titled “With Pino”Keep your existing logger, add LogNorth as a transport:
import pino from 'pino'import { transport } from '@karloscodes/lognorth-sdk/pino'
LogNorth.config('https://logs.yoursite.com', 'your-api-key')
const logger = pino({ level: 'info' }, transport())
logger.info({ user_id: 123 }, 'User signed up')Pass your logger to middleware:
app.use(middleware(logger))How It Works
Section titled “How It Works”| Method | Behavior |
|---|---|
LogNorth.log() | Batched (10 events or 5s) |
LogNorth.error() | Sent immediately with stack trace |
| Middleware | Logs requests with trace_id + duration_ms |
| Shutdown | Auto-flush on SIGINT/SIGTERM |
LogNorth.error() automatically captures the error class, file, line, caller function, and stack trace. These are used for three-tier issue grouping.