diff -u b/includes/common.inc b/includes/common.inc --- b/includes/common.inc +++ b/includes/common.inc @@ -5538,35 +5538,19 @@ watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); } else { - $queue_name_previous = ''; - // Make sure every queue exists. There is no harm in trying to recreate an // existing queue. foreach ($queues as $queue_name => $info) { - // Log a message saying that the queue started. - watchdog('cron', 'Starting execution of queue @queue_name.', array( - '@queue_name' => $queue_name, - ), WATCHDOG_NOTICE); - - timer_start('cron_queue_' . $queue_name); DrupalQueue::get($queue_name)->createQueue(); - timer_stop('cron_queue_' . $queue_name); - - // Log a message saying that the queue ended. - watchdog('cron', 'Execution of queue @queue_name took @time.', array( - '@queue_name' => $queue_name, - '@time' => timer_read('cron_queue_' . $queue_name) . 'ms', - ), WATCHDOG_NOTICE); } - $module_previous = ''; - // Iterate through the modules calling their cron handlers (if any): foreach (module_implements('cron') as $module) { - // Log a message saying that the cron event started. - watchdog('cron', 'Starting execution of @module_cron().', array('@module' => $module), WATCHDOG_NOTICE); - - timer_start('cron_' . $module); + if (variable_get('cron_logging_enabled', TRUE)) { + // Log a message saying that the cron event started. + watchdog('cron', 'Starting execution of @module_cron().', array('@module' => $module), WATCHDOG_NOTICE); + timer_start('cron_' . $module); + } // Do not let an exception thrown by one module disturb another. try { @@ -5576,13 +5560,14 @@ watchdog_exception('cron', $e); } - timer_stop('cron_' . $module); - - // Log a message saying that the cron event ended. - watchdog('cron', 'Execution of @module_cron() took @time.', array( - '@module' => $module, - '@time' => timer_read('cron_' . $module) . 'ms', - ), WATCHDOG_NOTICE); + if (variable_get('cron_logging_enabled', TRUE)) { + timer_stop('cron_' . $module); + // Log a message saying that the cron event ended. + watchdog('cron', 'Execution of @module_cron() took @time.', array( + '@module' => $module, + '@time' => timer_read('cron_' . $module) . 'ms', + ), WATCHDOG_NOTICE); + } } // Record cron time. diff -u b/modules/dblog/dblog.test b/modules/dblog/dblog.test --- b/modules/dblog/dblog.test +++ b/modules/dblog/dblog.test @@ -147,6 +147,15 @@ // The number of log entries created. $logs_count = $current_id - $last_id; $this->assertEqual($logs_count, $cron_logs_expected, format_string('Cron added @count of @expected new log entries', array('@count' => $logs_count, '@expected' => $cron_logs_expected))); + + // Test the number of entries with "cron_logging_enabled" disabled. + variable_set('cron_logging_enabled', FALSE); + $last_id = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); + $this->cronRun(); + $current_id = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); + + // Only one final "cron is finished" message should be logged. + $this->assertEqual($current_id - $last_id, 1, format_string('Cron added one new log entry.')); } /** only in patch2: unchanged: --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -881,3 +881,12 @@ * prevention and revert to the original behaviour. */ # $conf['javascript_use_double_submit_protection'] = FALSE; + +/** + * Cron logging. + * + * By default drupal_cron_run() will log each execution of hook_cron() together + * with the execution time. Set this variable to FALSE in order to opt out of + * this behaviour. + */ +# $conf['cron_logging_enabled'] = TRUE;