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

colorlog.basicConfig does not accept '{' style #98

Closed
skjoedt opened this issue Mar 22, 2021 · 2 comments
Closed

colorlog.basicConfig does not accept '{' style #98

skjoedt opened this issue Mar 22, 2021 · 2 comments

Comments

@skjoedt
Copy link

skjoedt commented Mar 22, 2021

Using colorlog.basicConfig() with style='{' results in an error. It seems that colorlog does not send the style on to logging.

import logging
import colorlog

fmt = '{log_color}{levelname} {name}: {message}'
colorlog.basicConfig(level=logging.DEBUG, style='{', format=fmt, stream=None)

log = logging.getLogger()

log.debug('hello')

Traceback

$ python3 test_log.py 
Traceback (most recent call last):
  File "test_log.py", line 6, in <module>
    colorlog.basicConfig(level=logging.DEBUG, style='{', format=fmt, stream=None)
  File "/home/csh/dev/wm/virt/lib/python3.8/site-packages/colorlog/logging.py", line 16, in basicConfig
    logging.basicConfig(**kwargs)
  File "/toolbox/2/tools/python-3.8.1/lib/python3.8/logging/__init__.py", line 1984, in basicConfig
    fmt = Formatter(fs, dfs, style)
  File "/toolbox/2/tools/python-3.8.1/lib/python3.8/logging/__init__.py", line 576, in __init__
    self._style.validate()
  File "/toolbox/2/tools/python-3.8.1/lib/python3.8/logging/__init__.py", line 429, in validate
    raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0]))
ValueError: Invalid format '{log_color}{levelname} {name}: {message}' for '%' style

Using colorlog 4.7.2

@borntyping
Copy link
Owner

I was quite suprised to find this doesn't work - the bug has been around for a very long time! It resulted from passing some formatting aguments on to the original logging.basicConfig() (format and dateformat) but not others (style).

@borntyping
Copy link
Owner

Should be fixed in 4.8.0. Thanks!

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