Drupal 5.x backport of watchdog hook for custom logging and alerts via module

kbahey - June 4, 2007 - 22:37
Project:Drupal
Version:5.x-dev
Component:watchdog.module
Category:feature request
Priority:normal
Assigned:kbahey
Status:won't fix
Description

There was interest in having the same functionality that is now in Drupal 6: watchdog hook to enable customized logging and alerts via modules.

Here is a patch for this, tested against 5.1.

Some notes:

1. The patch has the dblog.module and syslog.module in it.

2. If you install this against an pristine tar ball that has yet to be installed, it should work seamlessly, with no warnings. However, if you install it on a site that has already been installed, you will get a warning about the watchdog table already being there. It is safe to ignore this warning. You also don't need to worry about this if you will NOT be using the dblog module.

3. If you decide to use the dblog module, you need to run update.php so that the severity level will be correct for the old entries in the watchdog table. It remains to be seen what will happen when you upgrade to Drupal 6.x, because it will try to once again change the severity codes. Since the watchdog entries are transient in nature, it is safe to just delete rows prior to the upgrade.

To core committers: I do not expect this to go in the 5.x branch, rather it is here for anyone to apply locally to their Drupal 5.x installation if they want. So, no need to bother yourself with it.

AttachmentSize
logging-5.1-4.patch37.32 KB

#1

drumm - June 5, 2007 - 08:44
Status:needs review» won't fix

Correct, this will not go into 5.x.

#2

Richard Eriksson - August 8, 2007 - 21:39

dblog.module might need a slight modification. I periodically get the following error:

Fatal error: Call to undefined function: arg() in /var/www/DRUPAL-5/html/modules/dblog/dblog.module on line 98

The change at https://svn.bryght.com/dev/changeset/799 and I attached a patch generated by 'svn diff' between the revisions. Credit goes to Steven, who explained to me that hook_init doesn't work quite the same way in Drupal 5 as it does in Drupal 6, and that arg() isn't available to dblog_init() in the Drupal 5 version. The way to get around it is to use hook_menu.

AttachmentSize
dblog-missing-arg-function.patch.txt 3.57 KB

#3

Richard Eriksson - August 9, 2007 - 21:30

Patch was malformed. Trying again.

AttachmentSize
dblog-missing-arg-function.patch_0.txt 3.47 KB

#4

John Morahan - September 25, 2007 - 17:06

I couldn't get Richard's patch to apply, but I made the change he described (using hook_menu instead of hook_init) and rerolled the whole thing against 5.2

AttachmentSize
watchdog-combined-5.2.patch 37.86 KB

#5

Hetta - January 17, 2008 - 08:56

xx (wrong project, sorry)

#6

Hetta - January 17, 2008 - 08:56

(xx)

#7

Richard Eriksson - December 7, 2007 - 00:57

Here's a patch that applies to Drupal 5.5. Well, except for deleting watchdog.info, which I got stuck on. Everything else applies to a stock Drupal 5.5 install, however.

AttachmentSize
watchdog-hook-5.5.patch.txt 36.97 KB

#8

Richard Eriksson - January 11, 2008 - 01:40

Here's the patch for the newly-released Drupal 5.6. It even deletes watchdog.info for you!

AttachmentSize
watchdog-hook-5.6.patch.txt 37.69 KB

#9

Richard Eriksson - January 29, 2008 - 18:58

A patch that applies to Drupal 5.7. (The patch for 5.6 applies just fine, with some offsets, but might as well make an 'official' version too.)

AttachmentSize
watchdog-hook-5.7.patch.txt 38.41 KB

#10

Richard Eriksson - July 9, 2008 - 23:32

The patch appears to apply nicely to a clean install of Drupal 5.8, so attaching a renamed file with the exact contents of previous patch.

AttachmentSize
watchdog-hook-5.8.patch.txt 38.41 KB

#11

Richard Eriksson - July 24, 2008 - 01:21

Same with 5.9, the patch appears to apply cleanly. Attaching a renamed patch file, but the contents are exactly the same.

AttachmentSize
watchdog-hook-5.9.patch.txt 38.41 KB

#12

ipsocannibal - July 25, 2008 - 18:54

I've noticed something strange on my drupal install, drupal 5.7, with this patch applied. After applying this patch whenever I set page caching to Normal I keep getting this error.

Fatal error: Call to undefined function arg() in "path to drupal install"/modules/dblog/dblog.module on line 88

This error corresponds to this method in the 5.7 version of the patch.

+function dblog_init() {
+  if (arg(0) == 'admin' && arg(1) == 'logs') {
+    // Add the CSS for this module
+    drupal_add_css(drupal_get_path('module', 'dblog') .'/dblog.css', 'module', 'all', FALSE);
+  }
+}

This function also appears in the 5.8 and 5.9 versions of the patch.

This is an excerpt from the drupal 5 api documentation of hook_init.

If you implement this hook and see an error like 'Call to undefined function', it is likely that you are depending on the presence of a module which has not been loaded yet. It is not loaded because Drupal is still in bootstrap mode. The usual fix is to move your code to hook_menu(!$may_cache).

My question is does this patch really need to include a dblog_init() function? Shouldn't the body of dblog_init() in this patch go inside dblog_menu()? Is anybody else experiencing this kind of problem? This issue has been mention previously so why does dblog_init() still exist in the newer versions of the patch?

I've included a patch to the dblog.module file for the 5.7 version of the patch. It tested it and it seems to work. It should work for the 5.8 and 5.9 versions as well but I haven't been able to test it under those versions.

AttachmentSize
dblog.module.patch 3.45 KB

#13

John Morahan - August 14, 2008 - 11:32
Title:Drupal 5.1 backport of watchdog hook for custom logging and alerts via module» Drupal 5.x backport of watchdog hook for custom logging and alerts via module

Combined the two patches and rerolled for 5.10

AttachmentSize
watchdog-hook-5.10.patch 33.84 KB

#14

kbahey - October 6, 2008 - 00:01

The patch in #13 did not apply cleanly for me.

So, I rerolled another one that includes the fix in #12 for dblog complaining about arg().

It also contains another important fix: in some cases, php errors very early on cause watchdog() to be called, and if this is too early for watchdog to have been initialized, a WSOD can happen. So, the call to module_implements() is wrapped in a function_exists(), so this would not happen.

This can happen if you have for example an undefined variable in settings.php.

This patch has a fix for this.

AttachmentSize
watchdog-hook-5.10.patch.txt 20.62 KB

#15

kbahey - October 6, 2008 - 18:02

The new modules were missing from the previous patch.

Here is an updated patch that includes the syslog and dblog patches.

AttachmentSize
watchdog-hook-5.10.patch.txt 39.84 KB

#16

Richard Eriksson - December 11, 2008 - 21:03

A patch that applies to Drupal 5.14.

AttachmentSize
watchdog-hook-5.14.patch 39.81 KB

#17

Richard Eriksson - January 15, 2009 - 00:27

A patch that applies to Drupal 5.15. Only change from the previous patch is accounting for an offset.

AttachmentSize
watchdog-hook-5.15.patch 39.81 KB

#18

Richard Eriksson - July 9, 2009 - 21:59

A patch that applies to Drupal 5.19. Same as last comment, the only change is accounting for an offset.

AttachmentSize
watchdog-hook-5.19.patch 39.81 KB

#19

Richard Eriksson - September 24, 2009 - 01:43

The patch in #18 applies cleanly to Drupal 5.20, but I'm attaching a renamed patch anyway. It's exactly the same as #18.

AttachmentSize
watchdog-hook-5.20.patch 39.81 KB

#20

John Morahan - October 30, 2009 - 20:08

fix suggested by litwol in irc: callback arguments should be an array (I have not tested)

AttachmentSize
watchdog-hook-5.20-litwol.patch 37.79 KB

#21

John Morahan - October 30, 2009 - 20:29

cvs version

AttachmentSize
watchdog-hook-5.20-litwol-cvs.patch 37.65 KB

#22

John Morahan - October 30, 2009 - 20:58

that should be in !$may_cache too, shouldn't it.

AttachmentSize
watchdog-hook-5.20-may_cache.patch 37.72 KB
 
 

Drupal is a registered trademark of Dries Buytaert.