Closed afeblot closed 3 weeks ago
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?
dev.ConsoleRenderer
level_styles
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)
structlog.configure()
my_styles
I believe #669 fixed this; feel free to comment/reopen if not.
Hi Hynek,
Yes, it does, thanks a lot. I also had to update a couple of tests due to https://github.com/hynek/structlog/issues/638
Is it expected that
dev.ConsoleRenderer
changes the value of my style variable passed with thelevel_styles
argument, instead of copying it and modifying its own copy?Demo:
Output:
(I'm calling
structlog.configure()
, in which I construct thedev.ConsoleRenderer
, and I do this multiple times in my unittests, whereasmy_styles
is a global variable, and supposed to remain constant)