Skip to content

feat: commonLoggerCreate with a context, a pino-style child logger - #159

Merged
fiddur merged 8 commits into
mainfrom
CodeQuality-logger-context
Sep 23, 2026
Merged

fiddur merged 8 commits into
mainfrom
CodeQuality-logger-context

Conversation

@fiddur

@fiddur fiddur commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Adding a logger context object.

  • commonLoggerCreate(sink, context) makes a contextful logger: every call emits one object { ...context, ...plainObjectArgs, err?, msg? }
  • child(context) merges context, and the sink can be a CommonLogger such as console.

The backend-lib changes makes the GCP sink write such an entry as structured jsonPayload fields (msg becomes message, an Error in err is serialized with its stack kept in message); separable if we want only the js-lib API here.

…ed context object

Appends one tagged, frozen context object as the last argument of every log call.
Wrapping a context logger merges (new keys win) instead of nesting; splitLogContext lets sinks lift it.
writeGCPStructuredLog spreads the context as top-level jsonPayload fields, meta last so severity and trace win.
devLogger prints the context dimmed after the message.
…tyle entry per call

Replaces commonLoggerContext/splitLogContext. A context as second argument makes the logger contextful:
plain-object args are merged into the entry, the first Error becomes err, the rest is joined into msg.
child(context) merges. The sink may be a CommonLogger such as console.
…uctured fields

msg becomes message, an Error in err is serialized and its stack kept in message, meta is spread last.
devLogger prints msg, err and then the remaining fields dimmed.
@fiddur fiddur changed the title feat: commonLoggerContext, a pino.child-style context logger feat: commonLoggerCreate with a context, a pino-style child logger Sep 18, 2026
Replaces the two private isPlainObject copies in commonLogger and the backend-lib GCP sink.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The structured GCP path drops valid message fields and throws when logging circular structured data.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds a pino-style contextual logger with child contexts and structured logging support for backend sinks.

Changes:

  • Adds PlainObject detection and typing.
  • Extends commonLoggerCreate with contexts, child loggers, and structured arguments.
  • Updates GCP/development sinks and adds coverage.
File summaries
File Description
packages/js-lib/src/types.ts Adds PlainObject.
packages/js-lib/src/log/commonLogger.ts Implements contextual and child loggers.
packages/js-lib/src/log/commonLogger.test.ts Tests logger behavior.
packages/js-lib/src/is.util.ts Adds _isPlainObject.
packages/js-lib/src/is.util.test.ts Tests plain-object detection.
packages/backend-lib/src/server/logMiddleware.ts Handles structured log entries.
packages/backend-lib/src/server/logMiddleware.test.ts Tests backend logging behavior.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/backend-lib/src/server/logMiddleware.ts Outdated
Comment thread packages/backend-lib/src/server/logMiddleware.ts Outdated
Comment thread packages/js-lib/src/is.util.ts Outdated
@fiddur fiddur self-assigned this Sep 18, 2026
@fiddur
fiddur marked this pull request as ready for review September 18, 2026 08:29

@mrnagydavid mrnagydavid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Comment thread packages/backend-lib/src/server/logMiddleware.ts Outdated
Comment thread packages/backend-lib/src/server/logMiddleware.ts Outdated
@fiddur
fiddur merged commit 7fd304e into main Sep 23, 2026
3 checks passed
@fiddur
fiddur deleted the CodeQuality-logger-context branch September 23, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants