8000 refactor: remove abstract-logging and use optional chaining for logger by mcollina · Pull Request #6381 · fastify/fastify · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@mcollina
Copy link
Member
@mcollina mcollina commented Nov 2, 2025

⚠️ DO NOT MERGE - Experimental Performance Test

This PR is an experiment to measure the performance impact of removing abstract-logging and using native optional chaining (?.) instead.

Summary

  • Removes the abstract-logging dependency
  • Replaces no-op logger with null when logger: false
  • Uses optional chaining operator (?.) for all logger method calls
  • Updates tests to handle null logger

Changes

Core Changes

  • lib/logger-factory.js: Returns { logger: null, hasLogger: false } instead of abstract-logging instance
  • All logger method calls now use ?. operator (e.g., logger?.info())
  • All logger property accesses now use ?. operator (e.g., logger?.[kDisableRequestLogging])

Breaking Changes

  • BREAKING: When logger: false, fastify.log is now null instead of a no-op logger object
  • User code that accesses fastify.log without optional chaining will throw

Test Changes

  • Updated tests that expected no-op logger to handle null logger
  • Tests that assign to logger properties now require logger: true

Performance Impact

This PR exists to benchmark the performance impact of using optional chaining vs abstract-logging.

The hypothesis is that optional chaining may have a performance cost compared to calling no-op functions. This needs to be measured before considering this change for production.

Test Plan

  • All unit tests pass
  • Run benchmarks to compare performance
  • Measure impact on hot paths

Questions to Answer

  1. What is the performance impact of ?. operator vs calling no-op functions?
  2. Is the performance acceptable for production use?
  3. Does removing a dependency justify any performance loss?

🤖 Generated with Claude Code

Replace abstract-logging with native optional chaining operator (?.)
for handling cases where no logger is configured. When logger is
disabled (logger: false), fastify.log is now null instead of a
no-op logger object.

BREAKING CHANGE: When logger is disabled, fastify.log is now null
instead of a no-op logger object with stub methods.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants

0