function watchdog

Logs a system message.

Parameters

$type: The category to which this message belongs. Can be any string, but the general practice is to use the name of the module calling watchdog().

$message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.

$variables: Array of variables to replace in the message on display or array() if message is already translated or not possible to translate.

$severity: The severity of the message; one of the following values as defined in RFC 3164:

$link: A link to associate with the message.

See also

watchdog_severity_levels()

hook_watchdog()

115 calls to watchdog()
aggregator_form_category_submit in drupal/core/modules/aggregator/aggregator.admin.inc
Form submission handler for aggregator_form_category().
aggregator_refresh in drupal/core/modules/aggregator/aggregator.module
Checks a news feed for new items.
ajax_get_form in drupal/core/includes/ajax.inc
Gets a form submitted via #ajax during an Ajax callback.
authorize_access_denied_page in drupal/core/authorize.php
Renders a 403 access denied page for authorize.php.
BanDelete::submitForm in drupal/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php
Form submission handler.

... See full list

4 string references to 'watchdog'
bootstrap_hooks in drupal/core/includes/bootstrap.inc
Defines the critical hooks that force modules to always be loaded.
dblog_top in drupal/core/modules/dblog/dblog.admin.inc
Page callback: Shows the most frequent log messages of a given event type.
dblog_update_8001 in drupal/core/modules/dblog/dblog.install
Make *id fields unsigned.
UpdateModuleHandler::getImplementations in drupal/core/lib/Drupal/Core/Extension/UpdateModuleHandler.php
Implements \Drupal\Core\Extension\ModuleHandlerInterface::getImplementations().

File

drupal/core/includes/bootstrap.inc, line 1549
Functions that need to be loaded on every Drupal request.

Code

function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG_NOTICE, $link = NULL) {
  global $user, $base_root;
  static $in_error_state = FALSE;

  // It is possible that the error handling will itself trigger an error. In that case, we could
  // end up in an infinite loop. To avoid that, we implement a simple static semaphore.
  if (!$in_error_state && function_exists('module_implements')) {
    $in_error_state = TRUE;

    // The user object may not exist in all conditions, so 0 is substituted if needed.
    $user_uid = isset($user->uid) ? $user->uid : 0;

    // Prepare the fields to be logged
    $log_entry = array(
      'type' => $type,
      'message' => $message,
      'variables' => $variables,
      'severity' => $severity,
      'link' => $link,
      'user' => $user,
      'uid' => $user_uid,
      'request_uri' => $base_root . request_uri(),
      'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
      'ip' => Drupal::request()
        ->getClientIP(),
      // Request time isn't accurate for long processes, use time() instead.
      'timestamp' => time(),
    );

    // Call the logging hooks to log/process the message
    foreach (module_implements('watchdog') as $module) {
      $function = $module . '_watchdog';
      $function($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;
  }
}