globality-corp / flake8-logging-format

Flake8 extension to validate (lack of) logging format strings
Apache License 2.0
134 stars 21 forks source link

Use of extra field in message #32

Open jonyscathe opened 2 years ago

jonyscathe commented 2 years ago

Hi,

I'm a bit confused by your example of how logging should be done for non-constant data.

I don't think your example in the readme works.

logger.info(
    "Hello {world}",
    extra=dict(
        world="Earth"
    )
)

Just leads to "Hello {world}" being logged as the extra dictionary is for filling in format arguments. So something like:

logging.basicConfig(format="%(message)s %(world)s")
logger.info(
    "Hello",
    extra=dict(
        world="Earth"
    )
)

Will print out "Hello Earth", but obviously that isn't so useful for logging non-constant data that you don't want in every log message. Am I missing something in my logging config that allows the extra dict to be used as you suggest?