Skip to content

Add pino logger package#61

Merged
malessani merged 5 commits intomainfrom
feat/add-pino-logger
Feb 2, 2026
Merged

Add pino logger package#61
malessani merged 5 commits intomainfrom
feat/add-pino-logger

Conversation

@malessani
Copy link
Contributor

Closes #60

What I did

This PR will add a new package to use a shared logger configuration across projects.

import { honoHttpLogger } from '@commercelayer/hono-pino-logger'

app.use(honoHttpLogger())

There is also a minimalOutput configuration to reduce the log output.

How to test

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests).
  • Make sure to add/update documentation regarding your changes.
  • You are NOT deprecating/removing a feature.

@malessani malessani force-pushed the feat/add-pino-logger branch from 8caef00 to 8b8e562 Compare January 30, 2026 17:30
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 30, 2026

npm i https://pkg.pr.new/commercelayer/common-utils/@commercelayer/hono-pino-logger@61
npm i https://pkg.pr.new/commercelayer/common-utils/@commercelayer/organization-config@61

commit: e3fba33

@malessani malessani self-assigned this Jan 30, 2026
@malessani malessani added the enhancement New feature or request label Jan 30, 2026
@malessani malessani requested a review from Copilot January 30, 2026 19:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new @commercelayer/hono-pino-logger package that provides Pino logger middleware for Hono applications with built-in request/response logging support. The package is designed to work with @hono/node-server and offers features like pretty printing in development, configurable log levels, sensitive data redaction, and minimal output mode.

Changes:

  • New package @commercelayer/hono-pino-logger with logger creation utilities and Hono middleware
  • Test suite with unit tests for logger and middleware functionality
  • Comprehensive documentation including README with examples and usage patterns
  • Example applications demonstrating basic and advanced usage scenarios
  • GitHub workflow update to include the new package in pkg-pr-new publishing

Reviewed changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated 12 comments.

File Description
packages/hono-pino-logger/* Core package implementation with logger, middleware, types, and tests
examples/hono-pino-logger/* Example applications demonstrating basic and advanced usage
.github/workflows/pkg-pr-new.yaml Updated to include new package in CI/CD pipeline
pnpm-lock.yaml Dependency updates for new package and its dependencies
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

expect(middleware).toBeDefined()
expect(typeof middleware).toBe('function')
})
})
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minimalOutput configuration option is not covered by tests. This is a key feature mentioned in the PR description and README. Consider adding test cases to verify that when minimalOutput: true, the serializers and customProps are correctly set to undefined/return undefined, and the output excludes request_id, user_agent, ip, and detailed request/response objects.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +16
const {
logger = defaultLogger,
logRequestBody = false,
minimalOutput = false,
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logResponseBody configuration option is defined in the HttpLoggerConfig interface (types.ts line 48) and documented in the README, but it's never used in the middleware implementation. The config is destructured on line 16 but the value is not applied anywhere. Either implement this feature or remove it from the interface and documentation.

Copilot uses AI. Check for mistakes.
Comment on lines +134 to +138
// Map express-style middleware to Hono
await new Promise<void>((resolve) => httpLogger(req, res, () => resolve()))

// Attach logger to context for use in route handlers
c.set('logger', req.log)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The middleware wraps the pinoHttp call in a Promise but doesn't handle potential errors. If pinoHttp throws an error or the Promise rejects, it could crash the application. Consider adding error handling around line 135 to ensure the middleware fails gracefully and logs errors appropriately.

Suggested change
// Map express-style middleware to Hono
await new Promise<void>((resolve) => httpLogger(req, res, () => resolve()))
// Attach logger to context for use in route handlers
c.set('logger', req.log)
// Map express-style middleware to Hono with error handling
try {
await new Promise<void>((resolve, reject) => {
try {
;(httpLogger as any)(req, res, (err?: unknown) => {
if (err) {
reject(err)
return
}
resolve()
})
} catch (err) {
reject(err)
}
})
} catch (err) {
const logger = (c.get && (c.get('logger') as any)) || defaultLogger
if (logger && typeof logger.error === 'function') {
logger.error({ err }, 'Error in honoHttpLogger middleware')
}
// Continue to next middleware/handler even if logging failed
}
// Attach logger to context for use in route handlers, if available
if ((req as any).log) {
c.set('logger', (req as any).log)
}

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to +68
: {
req: (req) => {
return {
method: req.method,
url: req.url?.split('?')[0],
query: req.query,
body: logRequestBody ? req.body : undefined,
remote_address: req.remoteAddress,
remote_port: req.remotePort,
}
},
},
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serializers object when minimalOutput is false only defines a serializer for 'req', but doesn't include serializers for 'res' and 'err'. This means pino-http will use its default serializers for response and error objects. If you want to customize these as well (or if you want to ensure they follow the same pattern as the request serializer), consider adding explicit serializers for 'res' and 'err'. Alternatively, if the default serializers are acceptable, this is fine as-is.

Copilot uses AI. Check for mistakes.
@malessani malessani marked this pull request as ready for review February 2, 2026 11:27
@malessani malessani merged commit aa73d57 into main Feb 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add common pino logger configuration to use across project

4 participants