Skip to content

Add configurable Monolog field name - #38

Open
pforesi wants to merge 1 commit into
chrisguitarguy:mainfrom
pforesi:feature/make-request-id-record-name-configurable
Open

Add configurable Monolog field name#38
pforesi wants to merge 1 commit into
chrisguitarguy:mainfrom
pforesi:feature/make-request-id-record-name-configurable

Conversation

@pforesi

@pforesi pforesi commented Jan 23, 2026

Copy link
Copy Markdown

Add configurable Monolog field name

Description

This PR adds the ability to customize the field name used in Monolog's extra array to store the request ID. Previously, the field name was hardcoded as request_id.

What's Changed

New Configuration Option

  • Added monolog_field_name configuration parameter (defaults to request_id for backward compatibility)
  • The field name is exposed as a container parameter %chrisguitarguy_request_id.monolog_field_name%

Benefits

  • Flexibility: Users can now customize the field name to match their logging conventions
  • No duplication: The container parameter can be referenced in service definitions (e.g., Monolog formatters)
  • Backward compatible: Default value maintains existing behavior

Usage Example

Basic usage (default behavior)

chrisguitarguy_request_id:
    enable_monolog: true
    # monolog_field_name: request_id  # default value
Custom field name with container parameter
chrisguitarguy_request_id:
    monolog_field_name: my_request_id

services:
    custom_formatter:
        class: Monolog\Formatter\LineFormatter
        arguments:
            # Uses the container parameter - no duplication needed!
            - "[%%level_name%% - %%extra.%chrisguitarguy_request_id.monolog_field_name%%%] %%message%%"

Testing

✅ All existing tests pass (24 tests, 65 assertions)
✅ Added 2 new unit tests for custom field names (Monolog v1-2 and v3+)
✅ Added acceptance test to verify container parameter is correctly defined
✅ No breaking changes
Documentation
Updated README.md with configuration details and usage examples
Updated CHANGELOG.md with the new features
Added inline code documentation
Checklist
Code follows project style guidelines
Tests added for new functionality
Documentation updated
Backward compatible
All tests passing

- Add 'monolog_field_name' configuration option (defaults to 'request_id')
- Expose field name as container parameter for use in service definitions
- Add unit and acceptance tests for custom field names
- Update documentation with examples and best practices
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.

1 participant