Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Duplicate logs when using application factory #1856

Open
ulbwa opened this issue Oct 18, 2024 · 0 comments
Open

Bug: Duplicate logs when using application factory #1856

ulbwa opened this issue Oct 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ulbwa
Copy link
Contributor

ulbwa commented Oct 18, 2024

Describe the bug
When running the code using an application factory, logs are duplicated. If you uncomment the block of code that does not use the factory, logs are written three times. It appears that multiple instances of CriticalLogMiddleware are being created, even though only one middleware is listed in broker._middlewares.

How to reproduce
Include source code:

from faststream import FastStream
from faststream.nats import JStream, NatsBroker, NatsRouter

router = NatsRouter()


@router.subscriber("logtest", stream=JStream("some"), queue="some-logtest")
async def testhandler(message: str): ...


# b = NatsBroker()
# b.include_router(router)
# a = FastStream(b)


# @a.after_startup
# async def _():
#     await b.publish("logtest", "logtest")


def get_app():
    b = NatsBroker()
    b.include_router(router)
    a = FastStream(b)

    @a.after_startup
    async def _():
        await b.publish("logtest", "logtest")

    return a
@ulbwa ulbwa added the bug Something isn't working label Oct 18, 2024
@ulbwa ulbwa changed the title Bug: Bug: Duplicate logs when using application factory Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant