-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add all parameters to basicConfig #79
Comments
In theory, because I would expect this to throw an error if any of the formatter keyword arguments are set, but I don't currently have a machine available to reproduce this on. |
I see, weird that I do not get any errors then..But you are right! How about a function call to def basicConfig(formatter=None, **kwargs):
"""Call ``logging.basicConfig`` and override the formatter it creates."""
logging.basicConfig(**kwargs)
logging._acquireLock()
try:
if formatter is None:
formatter = ColoredFormatter(fmt=BASIC_FORMAT, datefmt=None)
stream = logging.root.handlers[0]
stream.setFormatter(formatter)
finally:
logging._releaseLock() Or if you wish to keep your level of similarity to the def basicConfig(style='%', log_colors=None, reset=True, secondary_log_colors=None, **kwargs):
"""Call ``logging.basicConfig`` and override the formatter it creates."""
logging.basicConfig(**kwargs)
logging._acquireLock()
try:
stream = logging.root.handlers[0]
stream.setFormatter(
ColoredFormatter(
fmt=kwargs.get('format', BASIC_FORMAT),
datefmt=kwargs.get('datefmt', None),
style=style,
log_colors=log_colors,
reset=reset,
secondary_log_colors=secondary_log_colors)))
finally:
logging._releaseLock() Unless there is another way to make sure that the cmd output is colored in the colors that I want, I think this functionality is really missing.. If there is a simple way to have my own colors in the cmd output (and I'm completely missing this), please let me know. |
That change would probably be a good improvement to the library! At the moment, the only option for customising the formatter is managing setup yourself - there are examples in the README but this is the shorted I can (theoretically) make it:
|
Which change do you mean? The first one or the second one? I tried it with the However, it would be very useful for my code if one of these changes was added to the package, would you like me to create a merge request for this? |
The second one - adding the extra parameters to
That probably shouldn't happen - did you still call |
Ok, perfect! I'll make a pull request then :)
I cannot reproduce the duplicate output with your example: #79 (comment) import logging
import colorlog
handler = colorlog.StreamHandler()
handler.setFormatter(
colorlog.ColoredFormatter(
fmt='%(log_color)s%(asctime)s %(levelname)-8s %(name)-15s - %(funcName)s - %(message)s',
datefmt="%Y-%m-%d %H-%M-%S",
log_colors={
'DEBUG': 'bold_purple',
'INFO': 'bold_white',
'WARNING': 'bold_yellow',
'ERROR': 'bold_red',
'CRITICAL': 'bold_red,bg_white',
}
)
)
logging.basicConfig(handlers=[handler])
logger = colorlog.getLogger(logger_name) The output is formatted correctly, but it is still not colored the way I pass it on in the |
Released in 4.4.0. |
Awesome package, very nicely done!
I was wondering why the
basicConfig
only has thefmt
anddatefmt
option instead of all theColoredFormatter
options since you directly use this class?I have added them like this and it seems to work fine. Perhaps I'm missing something in how to use the package but this way I can simply use the basicConfig without creating any new handlers etc. and still choose my own colors 👍
The text was updated successfully, but these errors were encountered: