Skip to content

Conversation

@dolfinus
Copy link

Pull Request

Description

I have logging config like this:

version: 1
disable_existing_loggers: false

filters:
    correlation_id:
        (): asgi_correlation_id.CorrelationIdFilter
        uuid_length: 32
        default_value: '-'

formatters:
    colored:
        class: coloredlogs.ColoredFormatter
        # Add correlation_id to log records
        format: '%(asctime)s.%(msecs)03d %(processName)s:%(process)d %(name)s:%(lineno)d [%(levelname)s] %(correlation_id)s %(message)s'
        datefmt: '%Y-%m-%d %H:%M:%S'

handlers:
    main:
        class: logging.StreamHandler
        formatter: colored
        filters: [correlation_id]
        stream: ext://sys.stdout

root:
    handlers: [main]
    level: INFO

Filter asgi_correlation_id.CorrelationIdFilter accepts kwargs uuid_length and default_value, so this requires using custom callable syntax - (): name instead of class: name.

Adding support for this.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Changes Made

  • Added new CustomCallableConfig which accepts callable name and arbitrary set of key-value args
  • Annotate filters, formatters and handlers accepting callable factories. Also QueueHandler/QueueListenerHandler support this syntax for args queue and listener
  • Added tests for constructing new configs from python code and from ini file. Maybe other file formats should be tested as well.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested the changes with real logging configuration scenarios

Test Cases

Documentation

  • I have updated the README.md if needed
  • I have added docstrings to new functions/classes
  • I have updated type hints where applicable

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have checked that my code doesn't introduce security vulnerabilities

Related Issues

Closes #(issue number) (if applicable)

Additional Notes

Any additional information or context about this PR.

@dolfinus dolfinus force-pushed the feature/callable-factory-config branch from 2546a23 to 845e5a3 Compare October 31, 2025 07:59
@dolfinus dolfinus force-pushed the feature/callable-factory-config branch from 845e5a3 to 46e210c Compare October 31, 2025 08:12
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