Add configurable logger with Pino for Node.js and browser support#367
Add configurable logger with Pino for Node.js and browser support#367
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@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>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
已完成。Node.js端已集成Pino作为日志实现,浏览器端保留简单的console实现。 Changes in commit 07718d5:
All 23 tests still passing. |
|
This PR is very large. Consider breaking it into smaller PRs for easier review. |
There was a problem hiding this comment.
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/createLoggerwith environment detection, formatting options, redaction, and child/tracing helpers. - Integrates the logger into
ObjectKerneland updatesPluginContexttyping 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
| private initPinoLogger() { | ||
| if (!this.isNode) return; | ||
|
|
||
| try { | ||
| // Dynamic import for Pino (Node.js only) | ||
| const pino = require('pino'); | ||
|
|
There was a problem hiding this comment.
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.
| 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'); |
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)json(structured),text(simple),pretty(colored via pino-pretty)Kernel Integration (
packages/core/src/kernel.ts)consolereferencesSchema Updates (
packages/spec/src/system/logger.zod.ts).optional().default()pattern per repo standardsDependencies (
packages/core/package.json)pino@^8.17.0for Node.js loggingpino-pretty@^10.3.0for development-friendly outputUsage
Technical Notes
Loggerinterface includes optionaldestroy()for resource cleanupOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.