how can i disable watchdog? or stop logging?

Comments

heine’s picture

Watchdog is a required module. Logging is always a good idea.

Why do you want to disable logging? Perhaps the problem you have (?) can be solved in another way.

--
Tips for posting to the forums

kiova’s picture

watch dog logs every move to the sql. so it writes on hdd everytime... for a faster system i want to test drupal without watchdog...

heine’s picture

I believe watchdog only logs user logins/logouts/registrations, adding new content certain other messages, but not 'every move'. Access logs are kept by the statistics module.

How many users does your site have that logging is a problem?

Anyway you can comment (//) db_query(args) from

function watchdog($type, $message, $severity = WATCHDOG_NOTICE, $link = NULL) {
  global $user;
  db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, request_uri(), $_SERVER['REMOTE_ADDR'], time());
}

in bootstrap.inc

PS It's not a good idea to disable watchdog. Do something on the hardware side...

--
Tips for posting to the forums

holydiver-1’s picture

what part would I comment out in drupal 5.10? The code in that section is slightly different.

nrgamble’s picture

Why:
You have access to your web server (Apache) logs and know your way around them. If you familiar with Apache's error log than you will be frustrated by the fact that you will end up with half your PHP issues in Watchdog and the other half in your error log. Why not just keep them all in one place (error log) that requires no database overhead and is, in my opinion, easier to read? Watchdog also logs all 404 errors, which also get logged in Apache's access log...so you avoid data duplication and more overhead.

How:
It will require committing the cardinal sin of hacking Drupal core...OH NO!!

First, we will disable Drupal's error_handler function by commenting out the following line in _drupal_bootstrap_full around or on line 1967 in common.inc:

set_error_handler('error_handler');

Then, find your watchdog() function in bootstrap.inc (around or on line 747) and add in the following switch statement in place of the db_query() call:

switch ($type) {
  case 'page not found':
    // just look at the apache access log: /var/log/(httpd|apache2)/access_log
    break;
  case 'php':
    // error_handler() was disabled in includes/common.inc:553 by commenting out set_error_handler() in includes/common.inc:1967
    // php errors will now end up one place: /var/log/(httpd|apache2)/error_log
    break;
  default:
    // let watchdog log everything else just to make sure nothing unexpectedly breaks
    db_query("INSERT INTO {watchdog} (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (%d, '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)", $user->uid, $type, $message, $severity, $link, $request_uri, referer_uri(), $_SERVER['REMOTE_ADDR'], time());
    break;
}
pkej’s picture

After looking set_error_handler I learned from the comments that I could use this code in my settings.php:


function my_error_handler($errno, $errstr, $errfile, $errline) {
	switch ($errno) {
		case E_NOTICE:
		case E_USER_NOTICE:
			$errors = "Notice";
			break;
		case E_WARNING:
		case E_USER_WARNING:
			$errors = "Warning";
			break;
		case E_ERROR:
		case E_USER_ERROR:
			$errors = "Error";
			break;
		default:
			$errors = "Unknown";
			break;
	}

	if (ini_get("display_errors"))
		printf ("<br />\n<b>%s</b>: %s in <b>%s</b> online <b>%d</b><br /><br />\n", $errors, $errstr, $errfile, $errline);
	if (ini_get("log_errors"))
		error_log(sprintf("PHP %s: %s in %s on line %d", $errors, errstr, $errfile, $errline));
	return true;
}

// set to the user defined error handler
set_error_handler("my_error_handler");

It works for PHP errors at least, since I can see the error handler taking control.

In 6.x in moduels/dblog.module the dblog_watchdog function can be completly commented out after function and until before the last closing curly brace, like this:

function dblog_watchdog($log = array()) {
/*  $current_db = db_set_active();
  db_query("INSERT INTO {watchdog}
    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)
    VALUES
    (%d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d)",
    $log['user']->uid,
    $log['type'],
    $log['message'],
    serialize($log['variables']),
    $log['severity'],
    $log['link'],
    $log['request_uri'],
    $log['referer'],
    $log['ip'],
    $log['timestamp']);

  if ($current_db) {
    db_set_active($current_db);
  }
*/
}

Which seems to work for me under xampp on osx.

Of course, the best option would be to change the dblog_watchdog function to write the log to a file, or to syslog, as per the same for php_errors.

There might be some way to hook into dblog_watchdog, so that you don't have to hack a core file.

Paul K Egell-Johnsen

pkej’s picture

The page requests became much more snappy after disabling the watchdog.

Paul K Egell-Johnsen

aterchin’s picture

following this, as one of our developers was curious about this too.

drupalfan81’s picture

what happened to the follow bottom. I hate to post on this with nothing to add, but since there is no follow button, I have my hands tied.

blamartin’s picture

Hi, I have drupal version 7.28 and with module devel you can totally disable Drupal error handlers.
Simply go to Settings of module Devel and set Error handlers option to none.
After that every PHP notice, warning, errors and fatal errors are logged in standard way to error.log file.

cj-a-min’s picture

@blamartin
Devel module is for developing. And is a security risk in production.
Use included syslog module to write log to os. Then uninstall dblog (Database logging) module.