Opened 11 years ago

Closed 8 years ago

Last modified 8 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 Changed 11 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:2 Changed 9 years ago by Caroline Simpson

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 Changed 9 years ago by Caroline Simpson

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

comment:4 Changed 9 years ago by Tim Graham

Patch needs improvement: set

I left comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.

comment:5 Changed 9 years ago by Caroline Simpson

Patch needs improvement: unset

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

comment:6 Changed 9 years ago by Caroline Simpson

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

comment:7 Changed 9 years ago by Berker Peksag

Version: 1.4master

comment:8 Changed 9 years ago by Tim Graham

Patch needs improvement: set

Reviewed PR & needs a rebase.

comment:9 Changed 9 years ago by Caroline Simpson

Patch needs improvement: unset

I've updated the patch and done a rebase.

comment:10 Changed 9 years ago by Caroline Simpson

Patch needs improvement: set

comment:11 Changed 8 years ago by Tim Graham

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Looks good, pending some minor cosmetic changes.

comment:12 Changed 8 years ago by Caroline Simpson

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

comment:13 Changed 8 years ago by Tim Graham <timograham@…>

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 Changed 8 years ago by Tim Graham <timograham@…>

In 85c52743:

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

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