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

Can't set the "logger" key in "get_logger(initial_values=...)" #295

Closed
borntyping opened this issue Jan 11, 2021 · 1 comment
Closed

Can't set the "logger" key in "get_logger(initial_values=...)" #295

borntyping opened this issue Jan 11, 2021 · 1 comment

Comments

@borntyping
Copy link

This makes using ConsoleRenderer without stdlib integration a little awkward. ConsoleRenderer looks for the logger key set by structlog.stdlib.add_logger_name, but we can't set that key as an initial value of a logger context (which would be useful with the default PrintLogger which doesn't store a name).

This might all be working as intended, or there might be a better way to do it - I'm finding structlog incredibly useful, thanks so much for writing it!

import structlog

structlog.configure(processors=[structlog.dev.ConsoleRenderer()])

structlog.get_logger().info("works as expected", logger=__name__)

structlog.get_logger(logger=__name__).info("raises an exception")
works as expected                        [__main__] 
Traceback (most recent call last):
  File "logger.py", line 6, in <module>
    structlog.get_logger(logger=__name__).info("raises an exception")
  File "/home/sam/.local/share/virtualenvs/xerographer-dzaWO-xh/lib/python3.8/site-packages/structlog/_config.py", line 132, in get_logger
    return wrap_logger(None, logger_factory_args=args, **initial_values)
TypeError: wrap_logger() got multiple values for argument 'logger'
@hynek hynek closed this as completed in b0be044 Feb 18, 2021
@hynek
Copy link
Owner

hynek commented Feb 18, 2021

Thank you for your kind words!

You can use logger_name now which doesn't clash.

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

No branches or pull requests

2 participants