diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 0dd19d5..019d1d8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -12,6 +12,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Lock\DatabaseLockBackend; use Drupal\Core\Lock\LockBackendInterface; +use Monolog\Logger; /** * @file @@ -1715,7 +1716,7 @@ function watchdog_exception($type, Exception $exception, $message = NULL, $varia * A link to associate with the message. * * @see watchdog_severity_levels() - * @see hook_watchdog() + * @see Monolog\Logger */ function watchdog($type, $message, array $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { global $user, $base_root; @@ -1733,7 +1734,6 @@ function watchdog($type, $message, array $variables = array(), $severity = WATCH // Prepare the fields to be logged $log_entry = array( 'type' => $type, - 'message' => $message, 'variables' => $variables, 'severity' => $severity, 'link' => $link, @@ -1746,11 +1746,38 @@ function watchdog($type, $message, array $variables = array(), $severity = WATCH 'timestamp' => time(), ); - // Call the logging hooks to log/process the message - foreach (module_implements('watchdog') as $module) { - module_invoke($module, 'watchdog', $log_entry); + // Translate the watchdog constant value to a Monolog value. + // @todo Switch the WATCHDOG constants to the straight Logger constants? + switch ($severity) { + case WATCHDOG_EMERGENCY: + $severity = Logger::EMERGENCY; + break; + case WATCHDOG_ALERT: + $severity = Logger::ALERT; + break; + case WATCHDOG_CRITICAL: + $severity = Logger::CRITICAL; + break; + case WATCHDOG_ERROR: + $severity = Logger::ERROR; + break; + case WATCHDOG_WARNING: + $severity = Logger::WARNING; + break; + case WATCHDOG_NOTICE: + $severity = Logger::NOTICE; + break; + case WATCHDOG_INFO: + $severity = Logger::INFO; + break; + case WATCHDOG_DEBUG: + $severity = Logger::DEBUG; + break; } + // Add the record to the logger. + drupal_container()->get('logger')->addRecord($severity, $message, $log_entry); + // It is critical that the semaphore is only cleared here, in the parent // watchdog() call (not outside the loop), to prevent recursive execution. $in_error_state = FALSE; diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 0225c9b..4042370 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -125,6 +125,10 @@ public function build(ContainerBuilder $container) { ->setFactoryClass('Drupal\Core\ExceptionController') ->setFactoryMethod('getExceptionListener'); + // Register services needed for the watchdog logging system. + $container->register('logger', 'Symfony\Bridge\Monolog\Logger') + ->addArgument('Drupal'); + $container->addCompilerPass(new RegisterMatchersPass()); $container->addCompilerPass(new RegisterNestedMatchersPass()); // Add a compiler pass for registering event subscribers. diff --git a/core/modules/action/lib/Drupal/action/Tests/LoopTest.php b/core/modules/action/lib/Drupal/action/Tests/LoopTest.php deleted file mode 100644 index 87fa08e..0000000 --- a/core/modules/action/lib/Drupal/action/Tests/LoopTest.php +++ /dev/null @@ -1,82 +0,0 @@ - 'Actions executing in a potentially infinite loop', - 'description' => 'Tests actions executing in a loop, and makes sure they abort properly.', - 'group' => 'Action', - ); - } - - /** - * Sets up a loop with 3 - 12 recursions, and sees if it aborts properly. - */ - function testActionLoop() { - $user = $this->drupalCreateUser(array('administer actions')); - $this->drupalLogin($user); - - $info = action_loop_test_action_info(); - $this->aid = action_save('action_loop_test_log', $info['action_loop_test_log']['type'], array(), $info['action_loop_test_log']['label']); - - // Delete any existing watchdog messages to clear the plethora of - // "Action added" messages from when Drupal was installed. - db_delete('watchdog')->execute(); - // To prevent this test from failing when xdebug is enabled, the maximum - // recursion level should be kept low enough to prevent the xdebug - // infinite recursion protection mechanism from aborting the request. - // See http://drupal.org/node/587634. - config('action.settings') - ->set('recursion_limit', 7) - ->save(); - $this->triggerActions(); - } - - /** - * Loops watchdog messages up to actions_max_stack times. - * - * Creates an infinite loop by causing a watchdog message to be set, - * which causes the actions to be triggered again, up to action_max_stack - * times. - */ - protected function triggerActions() { - $this->drupalGet('', array('query' => array('trigger_action_on_watchdog' => $this->aid))); - $expected = array(); - $expected[] = 'Triggering action loop'; - $recursion_limit = config('action.settings')->get('recursion_limit'); - for ($i = 1; $i <= $recursion_limit; $i++) { - $expected[] = "Test log #$i"; - } - $expected[] = 'Stack overflow: recursion limit for actions_do() has been reached. Stack is limited by %limit calls.'; - - $result = db_query("SELECT message FROM {watchdog} WHERE type = 'action_loop_test' OR type = 'action' ORDER BY wid"); - $loop_started = FALSE; - foreach ($result as $row) { - $expected_message = array_shift($expected); - $this->assertEqual($row->message, $expected_message, format_string('Expected message %expected, got %message.', array('%expected' => $expected_message, '%message' => $row->message))); - } - $this->assertTrue(empty($expected), 'All expected messages found.'); - } -} diff --git a/core/modules/action/tests/action_loop_test/action_loop_test.info b/core/modules/action/tests/action_loop_test/action_loop_test.info deleted file mode 100644 index 82a2810..0000000 --- a/core/modules/action/tests/action_loop_test/action_loop_test.info +++ /dev/null @@ -1,7 +0,0 @@ -name = Action loop test -description = Support module for action loop testing. -package = Testing -version = VERSION -core = 8.x -hidden = TRUE -dependencies[] = action diff --git a/core/modules/action/tests/action_loop_test/action_loop_test.install b/core/modules/action/tests/action_loop_test/action_loop_test.install deleted file mode 100644 index 7085aed..0000000 --- a/core/modules/action/tests/action_loop_test/action_loop_test.install +++ /dev/null @@ -1,8 +0,0 @@ - 'watchdog', - ); - // Fire the actions on the associated object ($log_entry) and the context - // variable. - $aids = (array) $_GET['trigger_action_on_watchdog']; - actions_do($aids, $log_entry, $context); -} - -/** - * Implements hook_init(). - */ -function action_loop_test_init() { - if (!empty($_GET['trigger_action_on_watchdog'])) { - watchdog_skip_semaphore('action_loop_test', 'Triggering action loop'); - } -} - -/** - * Implements hook_action_info(). - */ -function action_loop_test_action_info() { - return array( - 'action_loop_test_log' => array( - 'label' => t('Write a message to the log.'), - 'type' => 'system', - 'configurable' => FALSE, - 'triggers' => array('any'), - ), - ); -} - -/** - * Write a message to the log. - */ -function action_loop_test_log() { - $count = &drupal_static(__FUNCTION__, 0); - $count++; - watchdog_skip_semaphore('action_loop_test', "Test log #$count"); -} - -/** - * Replacement of the watchdog() function that eliminates the use of semaphores - * so that we can test the abortion of an action loop. - */ -function watchdog_skip_semaphore($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { - global $user, $base_root; - - // Prepare the fields to be logged - $log_entry = array( - 'type' => $type, - 'message' => $message, - 'variables' => $variables, - 'severity' => $severity, - 'link' => $link, - 'user' => $user, - 'uid' => isset($user->uid) ? $user->uid : 0, - 'request_uri' => $base_root . request_uri(), - 'referer' => $_SERVER['HTTP_REFERER'], - 'ip' => ip_address(), - 'timestamp' => REQUEST_TIME, - ); - - // Call the logging hooks to log/process the message - foreach (module_implements('watchdog') as $module) { - module_invoke($module, 'watchdog', $log_entry); - } -} diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 89efb57..95024a1 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -141,28 +141,6 @@ function _dblog_get_message_types() { } /** - * Implements hook_watchdog(). - * - * Note: Some values may be truncated to meet database column size restrictions. - */ -function dblog_watchdog(array $log_entry) { - Database::getConnection('default', 'default')->insert('watchdog') - ->fields(array( - 'uid' => $log_entry['uid'], - 'type' => substr($log_entry['type'], 0, 64), - 'message' => $log_entry['message'], - 'variables' => serialize($log_entry['variables']), - 'severity' => $log_entry['severity'], - 'link' => substr($log_entry['link'], 0, 255), - 'location' => $log_entry['request_uri'], - 'referer' => $log_entry['referer'], - 'hostname' => substr($log_entry['ip'], 0, 128), - 'timestamp' => $log_entry['timestamp'], - )) - ->execute(); -} - -/** * Implements hook_form_FORM_ID_alter() for system_logging_settings(). */ function dblog_form_system_logging_settings_alter(&$form, $form_state) { diff --git a/core/modules/dblog/lib/Drupal/dblog/DblogBundle.php b/core/modules/dblog/lib/Drupal/dblog/DblogBundle.php new file mode 100755 index 0000000..e54b148 --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/DblogBundle.php @@ -0,0 +1,32 @@ +register('logger.dbloghandler', 'Drupal\dblog\DblogHandler'); + + // Add the handler to the logging system. + $reference = new Reference('logger.dbloghandler'); + $container->getDefinition('logger') + ->addMethodCall('pushHandler', array($reference)); + } + +} diff --git a/core/modules/dblog/lib/Drupal/dblog/DblogHandler.php b/core/modules/dblog/lib/Drupal/dblog/DblogHandler.php new file mode 100755 index 0000000..c86e560 --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/DblogHandler.php @@ -0,0 +1,41 @@ +insert('watchdog') + ->fields(array( + 'uid' => $record['context']['uid'], + 'type' => substr($record['context']['type'], 0, 64), + 'message' => $record['message'], + 'variables' => serialize($record['context']['variables']), + 'severity' => $record['context']['severity'], + 'link' => substr($record['context']['link'], 0, 255), + 'location' => $record['context']['request_uri'], + 'referer' => $record['context']['referer'], + 'hostname' => substr($record['context']['ip'], 0, 128), + 'timestamp' => $record['context']['timestamp'], + )) + ->execute(); + } +} diff --git a/core/modules/syslog/config/syslog.settings.yml b/core/modules/syslog/config/syslog.settings.yml index 1aa5b90..7f17a98 100644 --- a/core/modules/syslog/config/syslog.settings.yml +++ b/core/modules/syslog/config/syslog.settings.yml @@ -1,3 +1,2 @@ identity: drupal -facility: '' -format: '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message' +facility: 8 # Facility defaults to the value of LOG_USER. diff --git a/core/modules/syslog/lib/Drupal/syslog/SyslogBundle.php b/core/modules/syslog/lib/Drupal/syslog/SyslogBundle.php new file mode 100755 index 0000000..f29bb24 --- /dev/null +++ b/core/modules/syslog/lib/Drupal/syslog/SyslogBundle.php @@ -0,0 +1,39 @@ +get('identity'); + $facility = $config->get('facility'); + $container->register('logger.sysloghandler', 'Monolog/Handler/SyslogHandler') + ->addArgument($ident) + ->addArgument('facility'); + + // Add the handler to the logging system. + $reference = new Reference('logger.sysloghandler'); + $container->getDefinition('logger') + ->addMethodCall('pushHandler', array($reference)); + } + +} diff --git a/core/modules/syslog/syslog.install b/core/modules/syslog/syslog.install index 5b2c41a..8c8b03e 100644 --- a/core/modules/syslog/syslog.install +++ b/core/modules/syslog/syslog.install @@ -26,7 +26,6 @@ function syslog_update_8000() { update_variables_to_config('syslog.settings', array( 'syslog_identity' => 'identity', 'syslog_facility' => 'facility', - 'syslog_format' => 'format', )); } diff --git a/core/modules/syslog/syslog.module b/core/modules/syslog/syslog.module index 8af77c1..7426e13 100644 --- a/core/modules/syslog/syslog.module +++ b/core/modules/syslog/syslog.module @@ -5,22 +5,6 @@ * Redirects logging messages to syslog. */ -if (defined('LOG_LOCAL0')) { - /** - * Sets the proper logging facility. - * - * Note that LOG_LOCAL0 through LOG_LOCAL7 are not available on Windows, so we - * check for availability. If LOG_LOCAL0 is defined by the PHP environment, we - * set that as the default; if not, we use LOG_USER. - * - * @see http://php.net/manual/function.syslog.php - */ - define('DEFAULT_SYSLOG_FACILITY', LOG_LOCAL0); -} -else { - define('DEFAULT_SYSLOG_FACILITY', LOG_USER); -} - /** * Implements hook_help(). */ @@ -62,12 +46,6 @@ function syslog_form_system_logging_settings_alter(&$form, &$form_state) { '#description' => t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help, ); } - $form['syslog_format'] = array( - '#type' => 'textarea', - '#title' => t('Syslog format'), - '#default_value' => $config->get('format'), - '#description' => t('Specify the format of the syslog entry. Available variables are:
!base_url
Base URL of the site.
!timestamp
Unix timestamp of the log entry.
!type
The category to which this message belongs.
!ip
IP address of the user triggering the message.
!request_uri
The requested URI.
!referer
HTTP Referer if available.
!uid
User ID.
!link
A link to associate with the message.
!message
The message to store in the log.
'), - ); $form['#submit'][] = 'syslog_logging_settings_submit'; } @@ -81,7 +59,6 @@ function syslog_logging_settings_submit($form, &$form_state) { config('syslog.settings') ->set('identity', $form_state['values']['syslog_identity']) ->set('facility', $form_state['values']['syslog_facility']) - ->set('format', $form_state['values']['syslog_format']) ->save(); } @@ -103,36 +80,3 @@ function syslog_facility_list() { LOG_LOCAL7 => 'LOG_LOCAL7', ); } - -/** - * Implements hook_watchdog(). - */ -function syslog_watchdog(array $log_entry) { - global $base_url; - - $log_init = &drupal_static(__FUNCTION__, FALSE); - $config = config('syslog.settings'); - - if (!$log_init) { - $log_init = TRUE; - $facility = $config->get('facility'); - if ($facility === '') { - $facility = defined('LOG_LOCAL0') ? LOG_LOCAL0 : LOG_USER; - } - openlog($config->get('identity'), LOG_NDELAY, $facility); - } - - $message = strtr($config->get('format'), array( - '!base_url' => $base_url, - '!timestamp' => $log_entry['timestamp'], - '!type' => $log_entry['type'], - '!ip' => $log_entry['ip'], - '!request_uri' => $log_entry['request_uri'], - '!referer' => $log_entry['referer'], - '!uid' => $log_entry['uid'], - '!link' => strip_tags($log_entry['link']), - '!message' => strip_tags(!isset($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])), - )); - - syslog($log_entry['severity'], $message); -} diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 2d09534..c77127c 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1968,94 +1968,6 @@ function hook_custom_theme() { } /** - * Log an event message. - * - * This hook allows modules to route log events to custom destinations, such as - * SMS, Email, pager, syslog, ...etc. - * - * @param array $log_entry - * An associative array containing the following keys: - * - type: The type of message for this entry. - * - user: The user object for the user who was logged in when the event - * happened. - * - uid: The user ID for the user who was logged in when the event happened. - * - request_uri: The request URI for the page the event happened in. - * - referer: The page that referred the user to the page where the event - * occurred. - * - ip: The IP address where the request for the page came from. - * - timestamp: The UNIX timestamp of the date/time the event occurred. - * - severity: The severity of the message; one of the following values as - * defined in @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink - * - WATCHDOG_EMERGENCY: Emergency, system is unusable. - * - WATCHDOG_ALERT: Alert, action must be taken immediately. - * - WATCHDOG_CRITICAL: Critical conditions. - * - WATCHDOG_ERROR: Error conditions. - * - WATCHDOG_WARNING: Warning conditions. - * - WATCHDOG_NOTICE: Normal but significant conditions. - * - WATCHDOG_INFO: Informational messages. - * - WATCHDOG_DEBUG: Debug-level messages. - * - link: An optional link provided by the module that called the watchdog() - * function. - * - message: The text of the message to be logged. Variables in the message - * are indicated by using placeholder strings alongside the variables - * argument to declare the value of the placeholders. See t() for - * documentation on how the message and variable parameters interact. - * - variables: An array of variables to be inserted into the message on - * display. Will be NULL or missing if a message is already translated or if - * the message is not possible to translate. - */ -function hook_watchdog(array $log_entry) { - global $base_url; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); - - $severity_list = array( - WATCHDOG_EMERGENCY => t('Emergency'), - WATCHDOG_ALERT => t('Alert'), - WATCHDOG_CRITICAL => t('Critical'), - WATCHDOG_ERROR => t('Error'), - WATCHDOG_WARNING => t('Warning'), - WATCHDOG_NOTICE => t('Notice'), - WATCHDOG_INFO => t('Info'), - WATCHDOG_DEBUG => t('Debug'), - ); - - $to = 'someone@example.com'; - $params = array(); - $params['subject'] = t('[@site_name] @severity_desc: Alert from your web site', array( - '@site_name' => config('system.site')->get('name'), - '@severity_desc' => $severity_list[$log_entry['severity']], - )); - - $params['message'] = "\nSite: @base_url"; - $params['message'] .= "\nSeverity: (@severity) @severity_desc"; - $params['message'] .= "\nTimestamp: @timestamp"; - $params['message'] .= "\nType: @type"; - $params['message'] .= "\nIP Address: @ip"; - $params['message'] .= "\nRequest URI: @request_uri"; - $params['message'] .= "\nReferrer URI: @referer_uri"; - $params['message'] .= "\nUser: (@uid) @name"; - $params['message'] .= "\nLink: @link"; - $params['message'] .= "\nMessage: \n\n@message"; - - $params['message'] = t($params['message'], array( - '@base_url' => $base_url, - '@severity' => $log_entry['severity'], - '@severity_desc' => $severity_list[$log_entry['severity']], - '@timestamp' => format_date($log_entry['timestamp']), - '@type' => $log_entry['type'], - '@ip' => $log_entry['ip'], - '@request_uri' => $log_entry['request_uri'], - '@referer_uri' => $log_entry['referer'], - '@uid' => $log_entry['uid'], - '@name' => $log_entry['user']->name, - '@link' => strip_tags($log_entry['link']), - '@message' => strip_tags($log_entry['message']), - )); - - drupal_mail('emaillog', 'entry', $to, $language_interface->langcode, $params); -} - -/** * Prepare a message based on parameters; called from drupal_mail(). * * Note that hook_mail(), unlike hook_mail_alter(), is only called on the