The $message argument to watchdog is intended to be a text replaceable string. The help says "Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders.".

Yet, there are only three places in core that use watchdog without replaceable arguments, which prevent an alternative watchdog implementation from aggregating results by query string. This is important because it prevents watchdog implementors from using the $message itself as a unique string representing the message. For example, every call to 'access denied' is logged as a separate message. What is a watchdog implementor wanted to group all these 'access denied' or 'page not found' messages together, without knowing that type is unique ... the type is often the module name, and you wouldn't want to necessarily say every watchdog in a module is unique.

I'm not sure that I've articulated this very well.

But these 3 watchdog's are preventing mongodb_watchdog from grouping log entries in a very efficient way.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

douggreen’s picture

FileSize
1.64 KB

updated patch with correct replaceable arguments

chx’s picture

Status: Needs review » Reviewed & tested by the community

Quite good fixes thanks.

chx’s picture

There is more than alternative implementations, it was supposed that watchdog messages are translatable strings.

chx’s picture

Found another.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, watchdog-constant-strings.patch, failed testing.

chx’s picture

Status: Needs work » Needs review

#4: watchdog-constant-strings.patch queued for re-testing.

chx’s picture

Status: Needs review » Reviewed & tested by the community

That was some testbot fluke...

ygerasimov’s picture

I was not able to find any other places where watchdog was used without replaceable arguments, so patch #4 looks complete.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Dave Reid’s picture

Priority: Normal » Major
Status: Fixed » Needs work

Um... this completely broke watchdog's 'top' 404 pages since all 404 reports contain the same message 'page not found: %q'. Try viewing admin/reports/page-not-found after a couple 404 pages have been hit. And I'm not sure how we can fix it since it requires a GROUP BY to distinguish per page.

Dave Reid’s picture

Title: watchdog should always use replaceable argument » [Regression] Watchdog should always use replaceable argument
Dave Reid’s picture

Issue tags: +redirect

This also broke redirect.module which uses the same kind of thing.

Dave Reid’s picture

Category: task » bug
Status: Needs work » Needs review
Issue tags: +Regression
FileSize
1.57 KB

Rolling back what broke core dblog and other contrib modules only.

Dave Reid’s picture

What is a watchdog implementor wanted to group all these 'access denied' or 'page not found' messages together, without knowing that type is unique

Um... type is unique and will be the same for these. I don't see what the problem with the pre-patched behavior is.

chx’s picture

http://api.drupal.org/api/function/watchdog/7

$message The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.

Dave Reid’s picture

Agreed that's the 'proper' thing to do, but this breaks functionality and I don't see an easy fix that won't require API changes which are *way* too late for D7. We need to just accept the fact that these two watchdog calls have to break the standard. I would like to figure out a better API to track 404s and 403s in D8. Right now using the watchdog table is the only way to extract that information.

Dave Reid’s picture

FileSize
1.25 KB

Patch re-rolled with the whitespace fix removed since it's already in.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Sure. We can make exceptions based on message type. Edit: by we i mean mongodb watchdog, translator and others who want the api to keep its contract :) core can have a more proper fix in D8.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Regression, -redirect

Automatically closed -- issue fixed for 2 weeks with no activity.

fgm’s picture

Issue summary: View changes
Status: Closed (fixed) » Fixed

FWIW, this is still present in D8 today. Resetting to "fixed" just so followers can be notified.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.