Skip to content

Add configurable logger with Pino for Node.js and browser support - #367

Merged
hotlong merged 5 commits into
mainfrom
copilot/add-configurable-logging-capability
Jan 29, 2026
Merged

hotlong merged 5 commits into
mainfrom
copilot/add-configurable-logging-capability

Conversation

Copilot AI commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Kernel requires logging that adapts to server (Node.js) and browser environments with configurable output formats, levels, and security controls.

Implementation

Universal Logger (packages/core/src/logger.ts)

  • Runtime detection: Node.js vs browser, auto-selects defaults
  • Node.js: Integrated Pino - high-performance, low-overhead structured logging
  • Browser: Lightweight console-based logger
  • Formats: json (structured), text (simple), pretty (colored via pino-pretty)
  • File logging with rotation via Pino transports (Node.js only)
  • Sensitive data redaction with Pino's native redact feature
  • Child loggers with inherited context using Pino.child()
  • Distributed tracing support (traceId/spanId)

Kernel Integration (packages/core/src/kernel.ts)

  • Logger config via constructor, injected into PluginContext
  • Replaced hardcoded console references

Schema Updates (packages/spec/src/system/logger.zod.ts)

  • Applied .optional().default() pattern per repo standards

Dependencies (packages/core/package.json)

  • Added pino@^8.17.0 for Node.js logging
  • Added pino-pretty@^10.3.0 for development-friendly output

Usage

// Kernel with logger config
const kernel = new ObjectKernel({
  logger: {
    level: 'debug',
    format: 'pretty',
    file: './logs/app.log',  // Node.js only
    redact: ['password', 'apiKey']
  }
});

// Plugin receives configured logger (Pino in Node.js)
const plugin: Plugin = {
  name: 'my-plugin',
  init: async (ctx) => {
    ctx.logger.info('Initialized', { version: '1.0.0' });
    ctx.logger.error('Failed', error, { context: 'db' });
  }
};

// Standalone logger
const logger = createLogger({ format: 'json' });
const childLogger = logger.child({ requestId: '123' });
const tracedLogger = logger.withTrace('trace-id', 'span-id');

Technical Notes

  • Node.js: Uses Pino for production-grade logging with minimal overhead
  • Browser: Simple console implementation, no external dependencies
  • Pino provides native support for transports, rotation, child loggers, and redaction
  • Logger interface includes optional destroy() for resource cleanup
  • 23 tests covering both runtime environments
Original prompt

内核应该提供可配置的日志能力,但需要兼顾服务端和浏览器端的运行模式。


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel

vercel Bot commented Jan 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jan 29, 2026 11:18pm

Request Review

@hotlong

hotlong commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

@copilot nodejs端可以接入pino,不要自己写完整的日志实现

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
…ogger file sharing, and test cleanup

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Add configurable logging capability for server and browser modes Add configurable logger with Node.js/browser runtime detection Jan 29, 2026
Copilot AI requested a review from hotlong January 29, 2026 22:57
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>

Copilot AI commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot nodejs端可以接入pino,不要自己写完整的日志实现

已完成。Node.js端已集成Pino作为日志实现,浏览器端保留简单的console实现。

Changes in commit 07718d5:

  • Added pino and pino-pretty dependencies
  • Refactored logger to use Pino for Node.js environments
  • Leveraged Pino's built-in features: transports, redaction, child loggers, and pretty printing
  • Updated documentation to highlight Pino integration

All 23 tests still passing.

Copilot AI changed the title Add configurable logger with Node.js/browser runtime detection Add configurable logger with Pino for Node.js and browser support Jan 29, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file protocol:system tests size/xl labels Jan 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR is very large. Consider breaking it into smaller PRs for easier review.

@hotlong
hotlong marked this pull request as ready for review January 29, 2026 23:21
Copilot AI review requested due to automatic review settings January 29, 2026 23:21
@hotlong
hotlong merged commit 2768088 into main Jan 29, 2026
9 of 11 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a universal, configurable logging system to the ObjectStack kernel that supports both Node.js (via Pino) and browser environments, and wires it through the plugin context.

Changes:

  • Introduces ObjectLogger / createLogger with environment detection, formatting options, redaction, and child/tracing helpers.
  • Integrates the logger into ObjectKernel and updates PluginContext typing accordingly.
  • Adds logger configuration schema updates, Vitest setup, tests, and documentation/examples.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pnpm-lock.yaml Locks new dependencies for logger + tests.
packages/spec/src/system/logger.zod.ts Updates logger config schema defaults to .optional().default() pattern.
packages/core/vitest.config.ts Adds Vitest configuration for core package tests.
packages/core/src/types.ts Switches PluginContext.logger type from Console to the new Logger contract.
packages/core/src/logger.ts Adds universal logger implementation (Node + browser).
packages/core/src/logger.test.ts Adds unit tests for ObjectLogger.
packages/core/src/kernel.ts Injects configurable logger into kernel and plugin context; replaces console usage.
packages/core/src/kernel.test.ts Adds tests for kernel/logger integration.
packages/core/src/index.ts Exports the logger contract and implementation.
packages/core/src/contracts/logger.ts Adds Logger interface contract.
packages/core/package.json Adds Pino + pino-pretty dependencies and test scripts.
packages/core/README.md Documents configurable logging and updated kernel usage.
examples/basic/logger-example.ts Adds an end-to-end example demonstrating logger usage.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment on lines +51 to +57
private initPinoLogger() {
if (!this.isNode) return;

try {
// Dynamic import for Pino (Node.js only)
const pino = require('pino');

Copilot AI Jan 29, 2026

Copy link

Choose a reason for hiding this comment

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

packages/core is ESM (type: "module"), so require('pino') will throw at runtime and the logger will always fall back to console in Node. Switch to an ESM-compatible load (e.g., dynamic import('pino') with async/lazy initialization, or a Node-only module using createRequire + conditional exports) so Pino is actually usable.

Suggested change
private initPinoLogger() {
if (!this.isNode) return;
try {
// Dynamic import for Pino (Node.js only)
const pino = require('pino');
private async initPinoLogger() {
if (!this.isNode) return;
try {
// Dynamic import for Pino (Node.js only, ESM-compatible)
const { default: pino } = await import('pino');

Copilot uses AI. Check for mistakes.

This branch was successfully deployed

1 active deployment
Preview — d9adde6c Deployed Jan 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/xl tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants