Opened 12 years ago

Closed 9 years ago

Last modified 9 years ago

#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 Claude Paroz, 12 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Caroline Simpson, 10 years ago

Has patch: set
Owner: changed from nobody to Caroline Simpson
Status: newassigned

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.

comment:3 by Caroline Simpson, 10 years ago

The pull request has been updated to include the template name in the output.

comment:4 by Tim Graham, 10 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 Caroline Simpson, 9 years ago

Patch needs improvement: unset

I have submitted a new pull request with the updates requested for the previous pull request.

comment:6 by Caroline Simpson, 9 years ago

I've updated the pull request with fixes from review feedback.

comment:7 by Berker Peksag, 9 years ago

Version: 1.4master

comment:8 by Tim Graham, 9 years ago

Patch needs improvement: set

Reviewed PR & needs a rebase.

comment:9 by Caroline Simpson, 9 years ago

Patch needs improvement: unset

I've updated the patch and done a rebase.

comment:10 by Caroline Simpson, 9 years ago

Patch needs improvement: set

comment:11 by Tim Graham, 9 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Looks good, pending some minor cosmetic changes.

comment:12 by Caroline Simpson, 9 years ago

The latest review changes are now incorporated into the patch as well.

comment:13 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In dc5b01a:

Fixed #18773 -- Added logging for template variable resolving

Added a django.template logger without a default handler. Added
logging if there is an exception while resolving variables in a
template.

comment:14 by Tim Graham <timograham@…>, 9 years ago

In 85c52743:

Refs #18773 -- Improved template variable exception logging message.

Note: See TracTickets for help on using tickets.
Back to Top