fix(backend): replace honoLogger with pino-based HTTP logger#277
Merged
fix(backend): replace honoLogger with pino-based HTTP logger#277
Conversation
- Create custom HTTP logger middleware using existing pino logger - Output structured JSON with method, path, status, duration, traceId - Remove hono/logger import (no longer needed) - Enables proper parsing by Grafana/Loki in production Closes #274
There was a problem hiding this comment.
Pull request overview
This PR replaces Hono's default text-based logger middleware with a custom pino-based HTTP logger that outputs structured JSON logs suitable for parsing by Grafana/Loki in production environments. The implementation integrates with the existing trace middleware to include traceIds in HTTP request logs.
Key changes:
- Created a new HTTP logger middleware using the existing pino logger infrastructure
- Replaced
honoLogger()withhttpLogger()in the middleware chain - Logs include structured fields (method, path, status, duration, traceId) for observability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/src/lib/http-logger.ts | New HTTP logger middleware that wraps requests and logs them with structured pino output, including status-based log levels |
| backend/src/index.ts | Removed Hono's default logger import and replaced with custom httpLogger middleware |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace Hono's default
honoLogger()middleware with a custom pino-based HTTP logger to output structured JSON logs.Problem
The default
honoLogger()outputs human-readable text format:This cannot be parsed by Grafana/Loki in production environments.
Solution
Created a custom HTTP logger middleware that uses the existing pino logger:
method,path,status,duration,traceIdsource: "http.request"andcol1: "http"for log categorizationExample Output
Development (pino-pretty):
Production (JSON):
{"level":30,"time":1735389245092,"service":"m3w-backend","method":"GET","path":"/health","status":200,"duration":2,"traceId":"..."}Changes
backend/src/lib/http-logger.ts- New HTTP logger middlewarebackend/src/index.ts- ReplacehonoLogger()with custom middlewareTesting
npm testpassesCloses #274