log message in email without variables
mariuss - September 3, 2008 - 07:38
| Project: | Logging and alerts |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Description
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"

#1
Similar issue in drush module: #304711: watchdog show does not merge message with variables
#2
I attached a patch, please have a look.
#3
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.
#4
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.
#5
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.
#6
Automatically closed -- issue fixed for two weeks with no activity.
#7
I can see this issue happening again in 6.x-1.3.
#8
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 ...
#9
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.
#10
I committed a fix for this.
Either get it from CVS (DRUPAL-6--1 tag) or download the tarball after 24 hours have passed.
#11
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.
#12
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.
#13
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.
#14
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.#15
Automatically closed -- issue fixed for 2 weeks with no activity.
#16
subscribing
#17
@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.
#18
@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.
#19
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
#20
@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.
#21
#22
Resetting more issue settings...
#23
A 6.x-1.4 release should be available shortly. Thank you to kbaley for adding me as a co-maintainer.
#24
kbahey!
#25
@kbahey: Ah crap. My fingers wanted to tyep ai instead of a. My apologies. :(
#26
Automatically closed -- issue fixed for 2 weeks with no activity.