Django Logging Formatting Issue
See original GitHub issueHi @willmcgugan,
I would just like to ask about configuration for the logging formatting/handling within Django.
Following your post on your blog, I have attempted to configure my own logging within my Django project.
There are 2 major differences between what your blog post, and indeed the project’s README
displays when compared to my implementation.
For reference, your blog post’s screenshot:
The project’s README screenshot (albeit not Django):
My implementation displays as:
There are 2 issues with the way my logging is formatted:
-
You will see that my logging does not have the colorised formatting.
-
The width is somewhat constrained even though the width of my iTerm terminal window is plenty wide enough. Even when I widen it further, it remains constrained in its width.
It’s worth mentioning that my project is in Docker, so I don’t know if that’s an issue. I have also tested reviewing the development server output within the stock terminal
app in Mac OS which gave me the same result.
The timed grouping (with just the time element) and the warning levels both look good so it appears the Rich config is somewhat working.
@willmcgugan For reference, do you have an exact commit reference that points exactly to the settings.py
file you referred to in your blog post? Should it matter if it’s in Docker instead of just Django’s local development server?
I don’t know whether this is a config issue from my side, or whether there is a bug or missing feature from Rich itself.
My full logging config in my settings.py
file is:
...
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'skip_static_requests': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_static_requests,
}
},
'formatters': {
'rich': {'datefmt': '[%X]'},
},
'handlers': {
'console': {
'class': 'rich.logging.RichHandler',
'formatter': 'rich',
'level': 'INFO',
'filters': ['skip_static_requests'],
}
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
}
}
...
Please could you advise?
Many thanks,
Wayne
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top GitHub Comments
OK, following a bit more research, I found a solution to the issue.
There is a variable in
zsh
(and other Unix shells) calledCOLUMNS
. From this discovery, I then amended theDockerfile
responsible for the dev build and added a step within it’s build process:Someone else may need to customise that value for their desired window width.
After the rebuild, bringing the container (dev server) back up, and widening the iTerm window, it gave me the following:
Perfect!
For anyone wanting to use Django, Docker, and Rich together, I have recorded the overall solution to the issue in a commit.
Thanks for your help, @willmcgugan
Hi Will,
Further to above and your original answer, I did some research and found the following StackOverflow post.
It suggested that I need the following key adding to my
web
service (for my setup) within mydocker-compose.yml
file:Following that addition, then rebuilding my images and bring up the containers again, I now have…
As you can see, now I have colour, however the width still seems to be constrained to 80 chars.