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

dev.ConsoleRenderer modifies my own style variable #643

Closed
afeblot opened this issue Aug 31, 2024 · 2 comments · Fixed by #669
Closed

dev.ConsoleRenderer modifies my own style variable #643

afeblot opened this issue Aug 31, 2024 · 2 comments · Fixed by #669
Labels

Comments

@afeblot
Copy link

afeblot commented Aug 31, 2024

Is it expected that dev.ConsoleRenderer changes the value of my style variable passed with the level_styles argument, instead of copying it and modifying its own copy?

Demo:

import structlog

my_styles = structlog.dev.ConsoleRenderer.get_default_level_styles()

def check():
  structlog.dev.ConsoleRenderer(level_styles=my_styles)
  print(my_styles)

check()
check()
check()
check()

Output:

{'critical': '\x1b[31m\x1b[1m', 'exception': '\x1b[31m\x1b[1m', 'error': '\x1b[31m\x1b[1m', 'warn': '\x1b[33m\x1b[1m', 'warning': '\x1b[33m\x1b[1m', 'info': '\x1b[32m\x1b[1m', 'debug': '\x1b[32m\x1b[1m', 'notset': '\x1b[41m\x1b[1m'}
{'critical': '\x1b[31m\x1b[1m\x1b[1m', 'exception': '\x1b[31m\x1b[1m\x1b[1m', 'error': '\x1b[31m\x1b[1m\x1b[1m', 'warn': '\x1b[33m\x1b[1m\x1b[1m', 'warning': '\x1b[33m\x1b[1m\x1b[1m', 'info': '\x1b[32m\x1b[1m\x1b[1m', 'debug': '\x1b[32m\x1b[1m\x1b[1m', 'notset': '\x1b[41m\x1b[1m\x1b[1m'}
{'critical': '\x1b[31m\x1b[1m\x1b[1m\x1b[1m', 'exception': '\x1b[31m\x1b[1m\x1b[1m\x1b[1m', 'error': '\x1b[31m\x1b[1m\x1b[1m\x1b[1m', 'warn': '\x1b[33m\x1b[1m\x1b[1m\x1b[1m', 'warning': '\x1b[33m\x1b[1m\x1b[1m\x1b[1m', 'info': '\x1b[32m\x1b[1m\x1b[1m\x1b[1m', 'debug': '\x1b[32m\x1b[1m\x1b[1m\x1b[1m', 'notset': '\x1b[41m\x1b[1m\x1b[1m\x1b[1m'}
{'critical': '\x1b[31m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'exception': '\x1b[31m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'error': '\x1b[31m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'warn': '\x1b[33m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'warning': '\x1b[33m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'info': '\x1b[32m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'debug': '\x1b[32m\x1b[1m\x1b[1m\x1b[1m\x1b[1m', 'notset': '\x1b[41m\x1b[1m\x1b[1m\x1b[1m\x1b[1m'}

(I'm calling structlog.configure(), in which I construct the dev.ConsoleRenderer, and I do this multiple times in my unittests, whereas my_styles is a global variable, and supposed to remain constant)

@hynek
Copy link
Owner

hynek commented Nov 9, 2024

I believe #669 fixed this; feel free to comment/reopen if not.

@afeblot
Copy link
Author

afeblot commented Nov 9, 2024

Hi Hynek,

Yes, it does, thanks a lot.
I also had to update a couple of tests due to #638

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants