GithubHelp home page GithubHelp logo

Comments (3)

Kludex avatar Kludex commented on June 8, 2024

Can you give an MRE on which the change will benefit you?

from uvicorn.

josumoreno-BP avatar josumoreno-BP commented on June 8, 2024

Hey, see here an example:

import uvicorn 

async def app(scope, receive, send):
    assert scope['type'] == 'http'
    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [
            [b'content-type', b'text/plain'],
        ],
    })
    await send({
        'type': 'http.response.body',
        'body': b'Hello, world!',
    })

if __name__ == "__main__":
    LOG_CONFIG = {
        "version": 1,
        "disable_existing_loggers": False,
        "formatters": {
            "simple": {
                "format": "[%(levelname)s] %(message)s",
            },
        },
        "handlers": {
            "stdout": {
                "level": "NOTSET",
                "class": "logging.StreamHandler",
                "formatter": "simple",
                "stream": "ext://sys.stdout",
            }
        },
        "root": {
            "handlers": ["stdout"],
            "level": "WARNING",
        },
        "loggers": {
            "uvicorn": {
                "handlers": ["stdout"],
                "level": "INFO",
                "propagate": False,
            },
        },
    }
    uvicorn.run("main:app", log_config=LOG_CONFIG)

I'm setting uvicorn logger to log on level INFO, so every child logger (uvicorn.error, uvicorn.access, uvicorn.asgi, etc) will use that (unless something specific is declared for them). What this means is that no message logged by MessageLoggerMiddleware will be printed to stdout because they are logged at created level TRACE (5).

So the thing is that even having this config, uvicorn will still load the MessageLoggerMiddleware because I have not passed explicitly the log_level parameter. I think that "the need" of passing the log_level parameter along with the log_config (or having to declare the child logger levels explicitly in the log_config) is an unexpected behavior that leads to execute MessageLoggerMiddleware without needing it.

Checking getEffectiveLevel() will return the "real final" level that the logger will log in. So that's why I'm suggesting to change logger.level to logger.getEffectiveLevel() here.

Hope this helps to understand it. If this is still not clear, let me know.

from uvicorn.

Kludex avatar Kludex commented on June 8, 2024

Got it. Thanks. Do you mind creating a PR for it? 🙏

from uvicorn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.