Log messages sent in emails do not have the variables replaced.

For example, if you use watchdog to log a message like:
watchdog('test', 'Some message from !me', array('!me' => 'developer'), WATCHDOG_ERROR);

The the email will show the raw message: "Some message from !me"

What it should show is: "Some message from developer"

CommentFileSizeAuthor
#2 raw.patch740 bytesmariuss

Comments

mariuss’s picture

mariuss’s picture

Status: Active » Needs review
StatusFileSize
new740 bytes

I attached a patch, please have a look.

kbahey’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Needs review » Fixed

Committed to the -dev version.

Please wait for 24 hours and then download and test it. If it works I can make a stable release.

mariuss’s picture

Thanks for applying right away.

Please look at comment #3 in #304711: watchdog show does not merge message with variables, there still is a minor issue with localization. In this case that issue was there before this patch, so it can be considered as a totally different issue.

mariuss’s picture

I tested the patch, and I did not see any other changes. If this is the only change, you can go ahead and make a stable release.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

mariuss’s picture

Version: 6.x-1.x-dev » 6.x-1.3
Status: Closed (fixed) » Active

I can see this issue happening again in 6.x-1.3.

kbahey’s picture

How can that be?

Your patch had this:

- '@message' => strip_tags($log_msg['message']),
+ '@message' => strip_tags(strtr($log_msg['message'], $log_msg['variables'])),

But, if 'variables' was empty or not an array, we got errors, so I change it to this:

  if (is_array($log_msg['variables'] && !empty($log_msg['variables']))) {
    $msg = strtr($log_msg['message'], $log_msg['variables']);
  }
  else {
    $msg = $log_msg['message'];
  }

Then used $msg afterwards, which should do the same ...

mariuss’s picture

Not sure where the problem is, but here is a sample email:

Site:         http://example.com
Severity:     (3) Error
Timestamp:    Mon, 09/29/2008 - 22:26
Type:         php
IP Address:   192.139.120.147
Request URI:  http://example.com/cron.php
Referrer URI:
User:         (0)
Link:
Message:

%message in %file on line %line. 

The above error was the result of a broken PHP file, the whole site was failing, it first came up during cron.

There is no corresponding entry under "Recent log entries", so not sure how did "Logging and alerts" intercept this. Could be a different issue than the original one.

kbahey’s picture

Version: 6.x-1.3 » 6.x-1.x-dev

I committed a fix for this.

Either get it from CVS (DRUPAL-6--1 tag) or download the tarball after 24 hours have passed.

Nick Urban’s picture

Apologies if you already noticed this, but the problem with the variables not being substituted was just a matter of a misplaced parenthesis.

this:

  if (is_array($log_msg['variables'] && !empty($log_msg['variables']))) {

should be this:

  if (is_array($log_msg['variables']) && !empty($log_msg['variables'])) {

After that change, it works fine.

kbahey’s picture

Status: Active » Needs work

Can you please create a patch as per the instructions here http://drupal.org/patch, and attach it to the issue?

Make sure it is in unidiff format, tested and against the 6.x-1.x-dev tarball.

jonline’s picture

I found the following code problem and come here to report it but it seems already here.

<?php if (is_array($log_msg['variables']) && !empty($log_msg['variables'])) { ?>

please add this into upcoming releases.

dave reid’s picture

Status: Needs work » Fixed

The code has been changed to if (is_array($log_msg['variables'])) { in the 6.x-1.x-dev. This covers all bases and works just fine, so marking as fixed. We'll just have to wait for a release now.

Status: Fixed » Closed (fixed)

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

Andrew Schulman’s picture

subscribing

dave reid’s picture

@andrex593: It doesn't do much good to subscribe to a closed issue. Download the 6.x-1.x-dev version and you'll notice the problem is fixed.

Andrew Schulman’s picture

@Dave: Thanks, I did install the -dev version, and notice that the problem is fixed.

Nevertheless, it does do me some good to subscribe to a closed bug. (1) Sometimes closed bugs get reopened again, or there's further illuminating discussion. (2) If I have to apply a fix related to a bug, it helps me to have it in my bug list, so I can find it again easily when I have questions about it again in the future.

Thanks,
Andrew.

seanburlington’s picture

Version: 6.x-1.x-dev » 6.x-1.3
Status: Closed (fixed) » Needs work

Hi,
I read from above that this issue is fixed in the dev version

But the most recent CVS message is from December 2008 http://drupal.org/project/cvs/135107?nid=135107&nid=135107

I guess this is wrong - but without any info about what else might be in a nightly build I'm reluctant to install it.

Any chance of a stable release that includes this fix?

Thanks

dave reid’s picture

@seanburlington If you'd look at the project page you'd also notice that the 6.x-1.3 release was made on 2008-Sep-25, so if a commit was made on Dec 2008 (Dec comes after Sep), it's included only in the 6.x-1.x-dev version. I'm going to ask kbaley to see if I can help co-maintain this module and push out a new release.

dave reid’s picture

Status: Needs work » Fixed
dave reid’s picture

Version: 6.x-1.3 » 6.x-1.x-dev

Resetting more issue settings...

dave reid’s picture

A 6.x-1.4 release should be available shortly. Thank you to kbaley for adding me as a co-maintainer.

kbahey’s picture

kbahey!

dave reid’s picture

@kbahey: Ah crap. My fingers wanted to tyep ai instead of a. My apologies. :(

Status: Fixed » Closed (fixed)

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