#18773 closed New feature (fixed)
Enable optional logging of invalid variable lookups
| Reported by: | wrigley | Owned by: | Caroline Simpson |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Adding something like
# django/template/base.py
if getattr(settings,'TEMPLATE_LOG_IF_INVALID', False):
logging.getLogger(settings.TEMPLATE_LOG_IF_INVALID).debug(
"Failed lookup for key in [%s] in %r" %(bit,current))
around line 763, or whenever the silent_variable_failure is tested or something, would be awesome! That way there would be an easy way to check for invalid variables in the templates without compromising neither adminpages, layout or page reliability.
Then you could use something like:
# settings.py
TEMPLATE_LOG_IF_INVALID = 'invalid_log'
LOGGING = {
'version': 1,
'handlers': {
'console': {
'class': 'logger.StreamHandler',
'level': 'DEBUG'
}
},
'loggers': {
'invalid_log': {
'handlers': 'console',
'level': 'DEBUG'
}
}
}
a loglevel of WARNING might be more appropriate, but I'll leave that decision up to you guys, seeing as I am new to django and don't know neither the code base nor the conventions too well yet.
Cheers,
/J
Change History (14)
comment:1 by , 13 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 12 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:3 by , 12 years ago
The pull request has been updated to include the template name in the output.
comment:4 by , 11 years ago
| Patch needs improvement: | set |
|---|
I left comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.
comment:5 by , 11 years ago
| Patch needs improvement: | unset |
|---|
I have submitted a new pull request with the updates requested for the previous pull request.
comment:7 by , 11 years ago
| Version: | 1.4 → master |
|---|
comment:9 by , 11 years ago
| Patch needs improvement: | unset |
|---|
I've updated the patch and done a rebase.
comment:10 by , 11 years ago
| Patch needs improvement: | set |
|---|
comment:11 by , 11 years ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Looks good, pending some minor cosmetic changes.
I've submitted a pull request for this issue: https://github.com/django/django/pull/2552
Added a new logger, and log when there is an exception in the resolve function. The logger uses the null handler by default.