Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Logging in Django
Search
Jakh Daven
March 21, 2013
Programming
15k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Logging in Django
Jakh Daven
March 21, 2013
More Decks by Jakh Daven
See All by Jakh Daven
Developing Ubuntu Apps for fun and profit
tuxcanfly
0
110
Other Decks in Programming
See All in Programming
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
330
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.6k
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
160
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
140
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
360
AmebaブログはKMPから卒業します
kmars0605
0
320
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
210
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
280
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.7k
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
14
11k
ChromeでローカルLLM
ryu1013
0
200
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
Featured
See All Featured
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Skip the Path - Find Your Career Trail
mkilby
1
280
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Believing is Seeing
oripsolob
1
270
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
sira's awesome portfolio website redesign presentation
elsirapls
0
490
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
Visualization
eitanlees
153
17k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
650
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
570
Transcript
Logging in Django Javed Khan @tuxcanfly
Why bother • Archive of events • Hints for debugging
• Reproducing errors • Statistical Analysis
To log or not to log • Convenient message •
State variables • logger.debug(“details, details”) • logger.info(“Something wonderful is about to happen...”) • logger.warn(“I have a bad feeling about this”) • logger.error(“oops!”) • logger.critical(“oh no!”)
Teh codez from django.utils.log import getLogger logger = getLogger('django.request') if
request.method not in request_method_list: logger.warning('Method Not Allowed (%s): %s', request. method, request.path, extra={ 'status_code': 405, 'request': request } )
Terminology • formatters • filters • handlers • loggers
Log levels • debug • info • warning • error
• critical Other methods: • logger.log • logger.exception
Configuration - Dictconfig { 'version': 1, 'disable_existing_loggers': False, 'formatters': {
'standard': { 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' }, }, 'handlers': { 'default': { 'level':'INFO', 'class':'logging.StreamHandler', }, }, 'loggers': { '': { 'handlers': ['default'], 'level': 'INFO', 'propagate': True }, 'django.request': { 'handlers': ['default'], 'level': 'WARN', 'propagate': False }, } }
Configuration - Dictconfig formatters: 'formatters': { 'verbose': { 'format': '%(levelname)s
%(asctime)s %(module)s % (process)d %(thread)d %(message)s' }, 'simple': { 'format': '%(levelname)s %(message)s' }, }, asctime - 'Sun Jun 20 23:21:05 1993'.
Configuration - Dictconfig filters: 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse',
} }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' } }, class RequireDebugFalse(logging.Filter): def filter(self, record): return not settings.DEBUG
Configuration - Dictconfig handlers: 'handlers': { 'null': { 'level': 'DEBUG',
'class': 'django.utils.log.NullHandler', }, 'console':{ 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'simple' }, 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', 'filters': ['special'] } },
Configuration - Dictconfig handlers: • logging.handlers.RotatingFileHandler • logging.handlers.TimedRotatingFileHandler • logging.handlers.SMTPHandler
• logging.handlers.HTTPHandler
Configuration - Dictconfig loggers: 'loggers': { 'django': { 'handlers': ['null'],
'level': 'INFO', }, 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': False, }, 'foo.bar: { 'handlers': ['console', 'mail_admins'], 'level': 'INFO', 'filters': ['special'] } }
Common uses - debug sql 'handlers': { 'console': { 'level':
'DEBUG', 'class': 'logging.StreamHandler' } }, 'loggers': { 'django.db.backends': { 'handlers': ['console'], 'level': 'DEBUG', 'propagate': True, }, }
Common uses - filter sql 'filters': { 'sql_inserts': { '()':
'django.utils.log.CallbackFilter', 'callback': lambda x: 'INSERT' in x.msg } }, 'loggers': { 'django.db.backends': { 'handlers': ['console'], 'level': 'DEBUG', 'propagate': True, 'filters': ['sql_inserts'], }, }
Bonus Custom log levels: APOCALYPSE = 55 logging.addLevelName(APOCALYPSE, "APOCALYPSE") logger.log(APOCALYPSE,
"The end.")
Gotchas Circular import in Django < 1.5 settings.py: ... 'handlers':
{ 'default': { 'level':'INFO', 'class':'foo.bar.FooBarHandler', }, }, ... foo/bar.py: from django.conf import settings class FooBarHandler(object): ...
Gotchas Exception handler leaks secrets from django.views.decorators.debug import sensitive_variables, sensitive_post_parameters
@sensitive_post_parameters('password', 'credit_card_number') @sensitive_variables('password', 'credit_card_number') def my_super_secret_view(request): password = request.POST['password'] credit_card_number = request.POST['credit_card_number'] ... ---------- DEFAULT_EXCEPTION_REPORTER_FILTER = 'path.to.your.CustomExceptionReporterFilter' SafeExceptionReporterFilter HIDDEN_SETTINGS = re.compile ('API|TOKEN|KEY|SECRET|PASS|PROFANITIES_LIST|SIGNATURE')