Skip to content

fastapi-proxy-lib causes logging duplication #45

@dvarrazzo

Description

@dvarrazzo

The libraries calls loggin.debug() here:

logging.debug(
"HTTP: client:%s ; url:%s ; head:%s",
request.client,
proxy_request.url,
proxy_request.headers,
)

As a side effect, this function calls logging.basicConfig() if no handler is set on the root handler:

https://github.com/python/cpython/blob/5e65a1acc0b630397f1d190aed279114e6e99612/Lib/logging/__init__.py#L2204

This result in applications logging entries twice, if they don't use the root handler:

auth-api-c49b5985b-g8z7t api INFO:     test
auth-api-c49b5985b-g8z7t api INFO:authserver.routers.user_group_v2:test

as a workaround I am registering a null handler on the root logger:

logging.getLogger().addHandler(logging.NullHandler())

It's a bad practice for the library to call basicConfig(). Instead of the stupid top-level logging functions you should use your own logger, e.g.

# in core/http.py
import logging
logger = logging.getLogger("fastapi-proxy-lib")

...
logger.debug( 
     "HTTP: client:%s ; url:%s ; head:%s", 
     ...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions