Django logger (my personal favourite format)
article
2 min read
Personally, I do lot of programming using JAVA and log4j is my favourite package that I use on my project.. but sometimes I also use PYTHON and been using DJANGO framework
because of it simplicity and easier to deploy.
When I use DJANGO, I still prefer to have logger on each of importance line of code (LoC) so I can trace back what actually happened when the code are executed.
So, let share with you my simple, minimal and favourite format for DJANGO logging
python
# File : <project>/settings.py
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'formatters': {
'verbose': {
'format': '{asctime} | [{levelname}] | {name} | {message} - {filename}:{lineno}@{funcName} | [{module}/{process:d}/{'
'thread:d}] - ({pathname})',
'datefmt': '%Y-%m-%d %H:%M:%S',
'style': '{',
},
},
'root': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG')
},
}Then you use logger, you will getting something like below printed on console
log
2023-03-09 22:38:22 | [INFO] | django.utils.autoreload | Watching for file changes with StatReloader - autoreload.py:677@run_with_reloader | [autoreload/19692/16896] - (D:\PROJECT\WMS\robbi-hcom\venv\Lib\site-packages\django\utils\autoreload.py)
2023-03-09 22:41:09 | [INFO] | polls.views | Hello, world! - views.py:14@index | [views/19692/15420] - (D:\PROJECT\WMS\robbi-hcom\pearson\polls\views.py)
2023-03-09 22:42:23 | [INFO] | polls.views | someone vote on [<WSGIRequest: POST '/polls/1/vote/'>/1] - views.py:40@vote | [views/19692/15420] - (D:\PROJECT\WMS\robbi-hcom\pearson\polls\views.py)Cool isn’t? Hope my sharing is helpfull for the readers.
Have some thoughts, discussion or feedback on this post?
▸ What is webmention? How to send interactions!
Below you can find all of
webmention with this page.
You can also mention this URL on any website that supports WebMention.
Have you written a response to this post? Let me know the URL:Don't have WebMention? Use Comment Parade!
No webmentions yet.
Comments section coming soon. For now, send a webmention or email.