Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/pkg-pr-new.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: pkg-pr-new

on:
push:
branches:
- "**"
- "!main"
- "!release"
tags-ignore:
- "v*"
pull_request:
types: [ready_for_review]
branches-ignore:
- release

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false

- name: pnpm 🧰
uses: pnpm/action-setup@v4
with:
version: 10.x

- name: Node 🧰
uses: actions/setup-node@v6
with:
node-version: 24.x

- name: Install 📦
run: pnpm install --frozen-lockfile

- name: Build packages 🛠
run: pnpm build

- name: Publish 🚀 pkg.pr.new
run: |
npx pkg-pr-new publish \
'./packages/hono-pino-logger' \
'./packages/organization-config' \
--no-template
108 changes: 108 additions & 0 deletions examples/hono-pino-logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Hono Pino Logger - Examples

This directory contains examples demonstrating how to use `@commercelayer/hono-pino-logger` in a Hono application.

## Setup

Install dependencies (from the examples directory):

```bash
pnpm install
```

## Examples

### 1. Basic Example (`src/index.ts`)

Demonstrates basic usage with default configuration:
- Automatic request/response logging
- Request ID tracking
- Using logger in route handlers
- Different log levels (info, warn, error)

Run it:
```bash
pnpm dev
```

Then try:
```bash
# Basic request
curl http://localhost:3000/

# Get user
curl http://localhost:3000/users/123

# Create user
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"name":"Jane Doe","email":"jane@example.com"}'

# Trigger error
curl http://localhost:3000/error

# Trigger warning
curl http://localhost:3000/warn
```

### 2. Advanced Example (`src/advanced.ts`)

Demonstrates advanced features:
- Custom logger configuration
- Log level configuration
- Redacting sensitive data
- Child loggers with additional context
- Request body logging

Run it:
```bash
pnpm tsx src/advanced.ts
```

Then try:
```bash
# Login with sensitive data (password will be redacted)
curl -X POST http://localhost:3001/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"secret123"}'

# API with child logger
curl http://localhost:3001/api/data
```

## Expected Log Output

### Development (Pretty Print)
```
[2026-01-29 10:30:45] INFO: method=GET path=/users/123 status=200 duration=5ms
request_id: "abc-123-def"
user_agent: "curl/7.88.1"
ip: "::1"
userId: "123"
```

### Production (JSON)
```json
{
"level": "INFO",
"time": 1738152645000,
"msg": "method=GET path=/users/123 status=200 duration=5ms",
"request_id": "abc-123-def",
"userId": "123"
}
```

## Environment Variables

Control logging behavior with environment variables:

```bash
# Set log level
LOG_LEVEL=debug pnpm dev

# Production mode (JSON output)
NODE_ENV=production pnpm dev

# Development mode (Pretty output)
NODE_ENV=development pnpm dev
```
23 changes: 23 additions & 0 deletions examples/hono-pino-logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "hono-pino-logger-example",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "node dist/index.js",
"build": "tsc"
},
"dependencies": {
"@commercelayer/hono-pino-logger": "workspace:*",
"@hono/node-server": "^1.19.9",
"hono": "^4.11.7"
},
"devDependencies": {
"@types/node": "^24.10.1",
"pino": "^9.14.0",
"pino-pretty": "^13.1.3",
"tsx": "^4.21.0",
"typescript": "^5.9.3"
}
}
Loading
Loading