From 04bf43bb92ffa984b31e7d009b66aa4511b44075 Mon Sep 17 00:00:00 2001
From: webchick <drupal@webchick.net>
Date: Thu, 26 Jun 2014 11:55:12 -0700
Subject: [PATCH] Issue #2272467 by ParisLiakos: Remove usages of watchdog()
 from procedural code.

---
 core/authorize.php                            |  2 +-
 core/includes/bootstrap.inc                   | 29 ++++++++++---------
 core/includes/errors.inc                      |  2 +-
 core/includes/file.inc                        | 26 +++++++++--------
 core/includes/mail.inc                        |  2 +-
 core/includes/menu.inc                        |  2 +-
 core/includes/theme.inc                       |  2 +-
 core/includes/unicode.inc                     |  4 +--
 core/modules/file/file.api.php                |  8 ++---
 core/modules/file/file.module                 | 20 ++++++-------
 core/modules/filter/filter.module             |  2 +-
 core/modules/language/language.module         |  6 ++--
 core/modules/locale/locale.batch.inc          |  8 ++---
 core/modules/locale/locale.bulk.inc           | 11 +++----
 core/modules/locale/locale.module             | 11 +++----
 core/modules/system/entity.api.php            |  4 +--
 .../src/Tests/System/SettingsRewriteTest.php  |  4 +--
 core/modules/system/system.module             |  5 ++--
 core/modules/tracker/tracker.module           |  2 +-
 core/modules/user/user.module                 | 11 +++----
 core/modules/user/user.pages.inc              |  2 +-
 core/update.php                               |  2 +-
 22 files changed, 86 insertions(+), 79 deletions(-)

diff --git a/core/authorize.php b/core/authorize.php
index 96fe9aeb3b69..04c4e54f2ac0 100644
--- a/core/authorize.php
+++ b/core/authorize.php
@@ -140,7 +140,7 @@ function authorize_access_allowed() {
 }
 else {
   drupal_add_http_header('Status', '403 Forbidden');
-  watchdog('access denied', 'authorize.php', array(), WATCHDOG_WARNING);
+  \Drupal::logger('access denied')->warning('authorize.php');
   $page_title = t('Access denied');
   $output = t('You are not allowed to access this page.');
 }
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 6c7cf6f67849..7f8b179b9d26 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -813,20 +813,21 @@ function request_uri($omit_query_string = FALSE) {
  */
 function watchdog_exception($type, Exception $exception, $message = NULL, $variables = array(), $severity = WATCHDOG_ERROR, $link = NULL) {
 
-   // Use a default value if $message is not set.
-   if (empty($message)) {
-     // The exception message is run through
-     // \Drupal\Component\Utility\String::checkPlain() by
-     // \Drupal\Core\Utility\Error:decodeException().
-     $message = '%type: !message in %function (line %line of %file).';
-   }
-   // $variables must be an array so that we can add the exception information.
-   if (!is_array($variables)) {
-     $variables = array();
-   }
-
-   $variables += Error::decodeException($exception);
-   watchdog($type, $message, $variables, $severity, $link);
+  // Use a default value if $message is not set.
+  if (empty($message)) {
+    // The exception message is run through
+    // \Drupal\Component\Utility\String::checkPlain() by
+    // \Drupal\Core\Utility\Error:decodeException().
+    $message = '%type: !message in %function (line %line of %file).';
+  }
+
+  if ($link) {
+    $variables['link'] = $link;
+  }
+
+  $variables += Error::decodeException($exception);
+
+  \Drupal::logger($type)->log($severity, $message, $variables);
 }
 
 /**
diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index ebe1cd5cbda5..ead20d4b2c40 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -156,7 +156,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
     $number++;
   }
 
-  watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
+  \Drupal::logger('php')->log($error['severity_level'], '%type: !message in %function (line %line of %file).', $error);
 
   if (drupal_is_cli()) {
     if ($fatal) {
diff --git a/core/includes/file.inc b/core/includes/file.inc
index 1028f5e9b6b7..1166d4e1bbcf 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -616,7 +616,7 @@ function file_save_htaccess($directory, $private = TRUE, $force_overwrite = FALS
   }
   else {
     $variables = array('%directory' => $directory, '!htaccess' => '<br />' . nl2br(String::checkPlain($htaccess_lines)));
-    watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);
+    \Drupal::logger('security')->error("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables);
     return FALSE;
   }
 }
@@ -696,16 +696,17 @@ function file_valid_uri($uri) {
  */
 function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
   $original_source = $source;
+  $logger = \Drupal::logger('file');
 
   // Assert that the source file actually exists.
   if (!file_exists($source)) {
     // @todo Replace drupal_set_message() calls with exceptions instead.
     drupal_set_message(t('The specified file %file could not be copied because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $original_source)), 'error');
     if (($realpath = drupal_realpath($original_source)) !== FALSE) {
-      watchdog('file', 'File %file (%realpath) could not be copied because it does not exist.', array('%file' => $original_source, '%realpath' => $realpath));
+      $logger->notice('File %file (%realpath) could not be copied because it does not exist.', array('%file' => $original_source, '%realpath' => $realpath));
     }
     else {
-      watchdog('file', 'File %file could not be copied because it does not exist.', array('%file' => $original_source));
+      $logger->notice('File %file could not be copied because it does not exist.', array('%file' => $original_source));
     }
     return FALSE;
   }
@@ -726,7 +727,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
     $dirname = drupal_dirname($destination);
     if (!file_prepare_directory($dirname)) {
       // The destination is not valid.
-      watchdog('file', 'File %file could not be copied because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname));
+      $logger->notice('File %file could not be copied because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname));
       drupal_set_message(t('The specified file %file could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', array('%file' => $original_source)), 'error');
       return FALSE;
     }
@@ -736,7 +737,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
   $destination = file_destination($destination, $replace);
   if ($destination === FALSE) {
     drupal_set_message(t('The file %file could not be copied because a file by that name already exists in the destination directory.', array('%file' => $original_source)), 'error');
-    watchdog('file', 'File %file could not be copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $original_source, '%destination' => $destination));
+    $logger->notice('File %file could not be copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $original_source, '%destination' => $destination));
     return FALSE;
   }
 
@@ -745,7 +746,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
   $real_destination = drupal_realpath($destination);
   if ($source == $destination || ($real_source !== FALSE) && ($real_source == $real_destination)) {
     drupal_set_message(t('The specified file %file was not copied because it would overwrite itself.', array('%file' => $source)), 'error');
-    watchdog('file', 'File %file could not be copied because it would overwrite itself.', array('%file' => $source));
+    $logger->notice('File %file could not be copied because it would overwrite itself.', array('%file' => $source));
     return FALSE;
   }
   // Make sure the .htaccess files are present.
@@ -755,7 +756,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
     // If the copy failed and realpaths exist, retry the operation using them
     // instead.
     if ($real_source === FALSE || $real_destination === FALSE || !@copy($real_source, $real_destination)) {
-      watchdog('file', 'The specified file %file could not be copied to %destination.', array('%file' => $source, '%destination' => $destination), WATCHDOG_ERROR);
+      $logger->error('file', 'The specified file %file could not be copied to %destination.', array('%file' => $source, '%destination' => $destination));
       return FALSE;
     }
   }
@@ -1025,8 +1026,9 @@ function file_delete_multiple(array $fids) {
  * @see file_unmanaged_delete_recursive()
  */
 function file_unmanaged_delete($path) {
+  $logger = \Drupal::logger('file');
   if (is_dir($path)) {
-    watchdog('file', '%path is a directory and cannot be removed using file_unmanaged_delete().', array('%path' => $path), WATCHDOG_ERROR);
+    $logger->error('%path is a directory and cannot be removed using file_unmanaged_delete().', array('%path' => $path));
     return FALSE;
   }
   if (is_file($path)) {
@@ -1035,12 +1037,12 @@ function file_unmanaged_delete($path) {
   // Return TRUE for non-existent file, but log that nothing was actually
   // deleted, as the current state is the intended result.
   if (!file_exists($path)) {
-    watchdog('file', 'The file %path was not deleted because it does not exist.', array('%path' => $path), WATCHDOG_NOTICE);
+    $logger->notice('The file %path was not deleted because it does not exist.', array('%path' => $path));
     return TRUE;
   }
   // We cannot handle anything other than files and directories. Log an error
   // for everything else (sockets, symbolic links, etc).
-  watchdog('file', 'The file %path is not of a recognized type so it was not deleted.', array('%path' => $path), WATCHDOG_ERROR);
+  $logger->error('The file %path is not of a recognized type so it was not deleted.', array('%path' => $path));
   return FALSE;
 }
 
@@ -1256,7 +1258,7 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
       closedir($handle);
     }
     else {
-      watchdog('file', '@dir can not be opened', array('@dir' => $dir), WATCHDOG_ERROR);
+      \Drupal::logger('file')->error('@dir can not be opened', array('@dir' => $dir));
     }
   }
 
@@ -1350,7 +1352,7 @@ function drupal_chmod($uri, $mode = NULL) {
     return TRUE;
   }
 
-  watchdog('file', 'The file permissions could not be set on %uri.', array('%uri' => $uri), WATCHDOG_ERROR);
+  \Drupal::logger('file')->error('The file permissions could not be set on %uri.', array('%uri' => $uri));
   return FALSE;
 }
 
diff --git a/core/includes/mail.inc b/core/includes/mail.inc
index 09b8819a3394..e62297c5e2ee 100644
--- a/core/includes/mail.inc
+++ b/core/includes/mail.inc
@@ -184,7 +184,7 @@ function drupal_mail($module, $key, $to, $langcode, $params = array(), $reply =
       $message['result'] = $system->mail($message);
       // Log errors.
       if (!$message['result']) {
-        watchdog('mail', 'Error sending email (from %from to %to with reply-to %reply).', array('%from' => $message['from'], '%to' => $message['to'], '%reply' => $message['reply-to'] ? $message['reply-to'] : t('not set')), WATCHDOG_ERROR);
+        \Drupal::logger('mail')->error('Error sending email (from %from to %to with reply-to %reply).', array('%from' => $message['from'], '%to' => $message['to'], '%reply' => $message['reply-to'] ? $message['reply-to'] : t('not set')));
         drupal_set_message(t('Unable to send email. Contact the site administrator if the problem persists.'), 'error');
       }
     }
diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index 3b4b5c1fe26f..a6278ff8e6af 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -809,7 +809,7 @@ function menu_link_rebuild_defaults() {
       }
       else {
         if (empty($link['route_name']) && empty($link['link_path'])) {
-          watchdog('error', 'Menu_link %machine_name does neither provide a route_name nor a link_path, so it got skipped.', array('%machine_name' => $machine_name));
+          \Drupal::logger('menu_link')->error('Menu_link %machine_name does neither provide a route_name nor a link_path, so it got skipped.', array('%machine_name' => $machine_name));
           continue;
         }
         $menu_link = $menu_link_storage->createFromDefaultLink($link);
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 446134869180..38569ad132e1 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -459,7 +459,7 @@ function _theme($hook, $variables = array()) {
       // Only log a message when not trying theme suggestions ($hook being an
       // array).
       if (!isset($candidate)) {
-        watchdog('theme', 'Theme hook %hook not found.', array('%hook' => $hook), WATCHDOG_WARNING);
+        \Drupal::logger('theme')->warning('Theme hook %hook not found.', array('%hook' => $hook));
       }
       // There is no theme implementation for the hook passed. Return FALSE so
       // the function calling _theme() can differentiate between a hook that
diff --git a/core/includes/unicode.inc b/core/includes/unicode.inc
index 9540d424293f..27f1dd8c7f17 100644
--- a/core/includes/unicode.inc
+++ b/core/includes/unicode.inc
@@ -102,7 +102,7 @@ function drupal_xml_parser_create(&$data) {
       $data = preg_replace('/^(<\?xml[^>]+encoding)="(.+?)"/', '\\1="utf-8"', $out);
     }
     else {
-      watchdog('php', 'Could not convert XML encoding %s to UTF-8.', array('%s' => $encoding), WATCHDOG_WARNING);
+      \Drupal::logger('php')->warning('Could not convert XML encoding %s to UTF-8.', array('%s' => $encoding));
       return FALSE;
     }
   }
@@ -128,7 +128,7 @@ function drupal_xml_parser_create(&$data) {
 function drupal_convert_to_utf8($data, $encoding) {
   $out = Unicode::convertToUtf8($data, $encoding);
   if ($out === FALSE) {
-    watchdog('php', 'Unsupported encoding %s. Please install iconv, GNU recode or mbstring for PHP.', array('%s' => $encoding), WATCHDOG_ERROR);
+    \Drupal::logger('php')->error('Unsupported encoding %s. Please install iconv, GNU recode or mbstring for PHP.', array('%s' => $encoding));
   }
 
   return $out;
diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php
index 760f7f99d967..670569dee203 100644
--- a/core/modules/file/file.api.php
+++ b/core/modules/file/file.api.php
@@ -99,7 +99,7 @@ function hook_file_insert(Drupal\file\FileInterface $file) {
   // Add a message to the log, if the file is a jpg
   $validate = file_validate_extensions($file, 'jpg');
   if (empty($validate)) {
-    watchdog('file', 'A jpg has been added.');
+    \Drupal::logger('file')->notice('A jpg has been added.');
   }
 }
 
@@ -118,7 +118,7 @@ function hook_file_update(Drupal\file\FileInterface $file) {
     $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
     $file->save();
 
-    watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename())));
+    \Drupal::logger('file')->notice(t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename())));
   }
 }
 
@@ -138,7 +138,7 @@ function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterfa
     $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
     $file->save();
 
-    watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
+    \Drupal::logger('file')->notice(t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
   }
 }
 
@@ -158,7 +158,7 @@ function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterfa
     $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
     $file->save();
 
-    watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
+    \Drupal::logger('file')->notice(t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
   }
 }
 
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index e1f4b28027e0..3b3764dd7686 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -174,10 +174,10 @@ function file_usage() {
 function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
   if (!file_valid_uri($destination)) {
     if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
-      watchdog('file', 'File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
+      \Drupal::logger('file')->notice('File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
     }
     else {
-      watchdog('file', 'File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
+      \Drupal::logger('file')->notice('File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
     }
     drupal_set_message(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', array('%file' => $source->getFileUri())), 'error');
     return FALSE;
@@ -251,10 +251,10 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
 function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
   if (!file_valid_uri($destination)) {
     if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
-      watchdog('file', 'File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
+      \Drupal::logger('file')->notice('File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
     }
     else {
-      watchdog('file', 'File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
+      \Drupal::logger('file')->notice('File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
     }
     drupal_set_message(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', array('%file' => $source->getFileUri())), 'error');
     return FALSE;
@@ -522,7 +522,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
     $destination = file_default_scheme() . '://';
   }
   if (!file_valid_uri($destination)) {
-    watchdog('file', 'The data could not be saved because the destination %destination is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.', array('%destination' => $destination));
+    \Drupal::logger('file')->notice('The data could not be saved because the destination %destination is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.', array('%destination' => $destination));
     drupal_set_message(t('The data could not be saved because the destination is invalid. More information is available in the system log.'), 'error');
     return FALSE;
   }
@@ -732,11 +732,11 @@ function file_cron() {
           $file->delete();
         }
         else {
-          watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->getFileUri()), WATCHDOG_ERROR);
+          \Drupal::logger('file system')->error('Could not delete temporary file "%path" during garbage collection', array('%path' => $file->getFileUri()));
         }
       }
       else {
-        watchdog('file system', 'Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->getFileUri(), '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);
+        \Drupal::logger('file system')->info('Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->getFileUri(), '%modules' => implode(', ', array_keys($references))));
       }
     }
   }
@@ -958,7 +958,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
     $file->uri = $file->destination;
     if (!drupal_move_uploaded_file($file_info->getRealPath(), $file->getFileUri())) {
       drupal_set_message(t('File upload error. Could not move uploaded file.'), 'error');
-      watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri));
+      \Drupal::logger('file')->notice('Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri));
       $files[$i] = FALSE;
       continue;
     }
@@ -1510,7 +1510,7 @@ function file_managed_file_save_upload($element, array &$form_state) {
 
   $destination = isset($element['#upload_location']) ? $element['#upload_location'] : NULL;
   if (isset($destination) && !file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
-    watchdog('file', 'The upload directory %directory for the file field !name could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array('%directory' => $destination, '!name' => $element['#field_name']));
+    \Drupal::logger('file')->notice('The upload directory %directory for the file field !name could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array('%directory' => $destination, '!name' => $element['#field_name']));
     form_set_error($upload_name, $form_state, t('The file could not be uploaded.'));
     return FALSE;
   }
@@ -1520,7 +1520,7 @@ function file_managed_file_save_upload($element, array &$form_state) {
   $files_uploaded |= !$element['#multiple'] && !empty($file_upload);
   if ($files_uploaded) {
     if (!$files = file_save_upload($upload_name, $element['#upload_validators'], $destination)) {
-      watchdog('file', 'The file upload failed. %upload', array('%upload' => $upload_name));
+      \Drupal::logger('file')->notice('The file upload failed. %upload', array('%upload' => $upload_name));
       form_set_error($upload_name, $form_state, t('Files in the !name field were unable to be uploaded.', array('!name' => $element['#title'])));
       return array();
     }
diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index fde8921de45e..5e8fcbf11460 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -152,7 +152,7 @@ function filter_pre_render_text(array $element) {
   // If the requested text format does not exist, the text cannot be filtered.
   /** @var \Drupal\filter\Entity\FilterFormat $format **/
   if (!$format = entity_load('filter_format', $format_id)) {
-    watchdog('filter', 'Missing text format: %format.', array('%format' => $format_id), WATCHDOG_ALERT);
+    \Drupal::logger('filter')->alert('Missing text format: %format.', array('%format' => $format_id));
     $element['#markup'] = '';
     return $element;
   }
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index 8b1e7050af52..26e99ff9f00b 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -442,10 +442,10 @@ function language_save($language) {
   if ($language->is_new) {
     // Install any available language configuration overrides for the language.
     \Drupal::service('language.config_factory_override')->installLanguageOverrides($language->getId());
-    watchdog('language', 'The %language (%langcode) language has been created.', $t_args);
+    \Drupal::logger('language')->notice('The %language (%langcode) language has been created.', $t_args);
   }
   else {
-    watchdog('language', 'The %language (%langcode) language has been updated.', $t_args);
+    \Drupal::logger('language')->notice('The %language (%langcode) language has been updated.', $t_args);
   }
 
   return $language;
@@ -481,7 +481,7 @@ function language_delete($langcode) {
     }
 
     $t_args = array('%language' => $language->name, '%langcode' => $language->id);
-    watchdog('language', 'The %language (%langcode) language has been removed.', $t_args);
+    \Drupal::logger('language')->notice('The %language (%langcode) language has been removed.', $t_args);
     return TRUE;
   }
   return FALSE;
diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc
index 4e56890875d1..f2e7330292d0 100644
--- a/core/modules/locale/locale.batch.inc
+++ b/core/modules/locale/locale.batch.inc
@@ -228,7 +228,7 @@ function locale_translation_batch_fetch_finished($success, $results) {
  *   TRUE if the file is not found. FALSE if a fault occurred.
  */
 function locale_translation_http_check($uri) {
-
+  $logger = \Drupal::logger('locale');
   try {
     $response = \Drupal::httpClient()->head($uri);
     $result = array();
@@ -250,10 +250,10 @@ function locale_translation_http_check($uri) {
       // theme does not define the location of a translation file. By default
       // the file is checked at the translation server, but it will not be
       // found there.
-      watchdog('locale', 'Translation file not found: @uri.', array('@uri' => $uri));
+      $logger->notice('Translation file not found: @uri.', array('@uri' => $uri));
       return TRUE;
     }
-    watchdog('locale', 'HTTP request to @url failed with error: @error.', array('@url' => $uri, '@error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()));
+    $logger->notice('HTTP request to @url failed with error: @error.', array('@url' => $uri, '@error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()));
   }
 
   return FALSE;
@@ -285,6 +285,6 @@ function locale_translation_download_source($source_file, $directory = 'temporar
     $file->timestamp = filemtime($uri);
     return $file;
   }
-  watchdog('locale', 'Unable to download translation file @uri.', array('@uri' => $source_file->uri), WATCHDOG_ERROR);
+  \Drupal::logger('locale')->error('Unable to download translation file @uri.', array('@uri' => $source_file->uri));
   return FALSE;
 }
diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc
index ba5f4973e366..f1fe8e8fcabe 100644
--- a/core/modules/locale/locale.bulk.inc
+++ b/core/modules/locale/locale.bulk.inc
@@ -256,7 +256,7 @@ function locale_translate_batch_import($file, $options, &$context) {
     catch (Exception $exception) {
       // Import failed. Store the data of the failing file.
       $context['results']['failed_files'][] = $file;
-      watchdog('locale', 'Unable to import translations file: @file', array('@file' => $file->uri));
+      \Drupal::logger('locale')->notice('Unable to import translations file: @file', array('@file' => $file->uri));
     }
   }
 }
@@ -343,6 +343,7 @@ function locale_translate_batch_refresh(array &$context) {
  * Finished callback of system page locale import batch.
  */
 function locale_translate_batch_finished($success, $results) {
+  $logger = \Drupal::logger('locale');
   if ($success) {
     $additions = $updates = $deletes = $skips = $config = 0;
     if (isset($results['failed_files'])) {
@@ -374,7 +375,7 @@ function locale_translate_batch_finished($success, $results) {
         '@count translation files imported. %number translations were added, %update translations were updated and %delete translations were removed.',
         array('%number' => $additions, '%update' => $updates, '%delete' => $deletes)
       ));
-      watchdog('locale', 'Translations imported: %number added, %update updated, %delete removed.', array('%number' => $additions, '%update' => $updates, '%delete' => $deletes));
+      $logger->notice('Translations imported: %number added, %update updated, %delete removed.', array('%number' => $additions, '%update' => $updates, '%delete' => $deletes));
 
       if ($skips) {
         if (\Drupal::moduleHandler()->moduleExists('dblog')) {
@@ -384,7 +385,7 @@ function locale_translate_batch_finished($success, $results) {
           $message = format_plural($skips, 'One translation string was skipped because of disallowed or malformed HTML. See the log for details.', '@count translation strings were skipped because of disallowed or malformed HTML. See the log for details.');
         }
         drupal_set_message($message, 'warning');
-        watchdog('locale', '@count disallowed HTML string(s) in files: @files.', array('@count' => $skips, '@files' => implode(',', $skipped_files)), WATCHDOG_WARNING);
+        $logger->warning('@count disallowed HTML string(s) in files: @files.', array('@count' => $skips, '@files' => implode(',', $skipped_files)));
       }
     }
   }
@@ -606,11 +607,11 @@ function locale_config_batch_finished($success, array $results) {
     $configuration = isset($results['stats']['config']) ? $results['stats']['config'] : 0;
     if ($configuration) {
       drupal_set_message(t('The configuration was successfully updated. There are %number configuration objects updated.', array('%number' => $configuration)));
-      watchdog('locale', 'The configuration was successfully updated. %number configuration objects updated.', array('%number' => $configuration));
+      \Drupal::logger('locale')->notice('The configuration was successfully updated. %number configuration objects updated.', array('%number' => $configuration));
     }
     else {
       drupal_set_message(t('No configuration objects have been updated.'));
-      watchdog('locale', 'No configuration objects have been updated.', array(), WATCHDOG_WARNING);
+      \Drupal::logger('locale')->warning('No configuration objects have been updated.');
     }
   }
 }
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index eda544d4096d..179894b39812 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -1345,23 +1345,24 @@ function _locale_rebuild_js($langcode = NULL) {
   }
 
   // Log the operation and return success flag.
+  $logger = \Drupal::logger('locale');
   switch ($status) {
     case 'updated':
-      watchdog('locale', 'Updated JavaScript translation file for the language %language.', array('%language' => $language->name));
+      $logger->notice('Updated JavaScript translation file for the language %language.', array('%language' => $language->name));
       return TRUE;
 
     case 'rebuilt':
-      watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->id]), WATCHDOG_WARNING);
+      $logger->warning('JavaScript translation file %file.js was lost.', array('%file' => $locale_javascripts[$language->id]));
     // Proceed to the 'created' case as the JavaScript translation file has
     // been created again.
     case 'created':
-      watchdog('locale', 'Created JavaScript translation file for the language %language.', array('%language' => $language->name));
+      $logger->notice('Created JavaScript translation file for the language %language.', array('%language' => $language->name));
       return TRUE;
     case 'deleted':
-      watchdog('locale', 'Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->name));
+      $logger->notice('Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->name));
       return TRUE;
     case 'error':
-      watchdog('locale', 'An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->name), WATCHDOG_ERROR);
+      $logger->error('An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->name));
       return FALSE;
     default:
       // No operation needed.
diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php
index ddc302ab4c47..da1d53ec22d5 100644
--- a/core/modules/system/entity.api.php
+++ b/core/modules/system/entity.api.php
@@ -345,7 +345,7 @@ function hook_entity_translation_insert(\Drupal\Core\Entity\EntityInterface $tra
     '@language' => $translation->language()->name,
     '@label' => $translation->getUntranslated()->label(),
   );
-  watchdog('example', 'The @language translation of @label has just been stored.', $variables);
+  \Drupal::logger('example')->notice('The @language translation of @label has just been stored.', $variables);
 }
 
 /**
@@ -362,7 +362,7 @@ function hook_entity_translation_delete(\Drupal\Core\Entity\EntityInterface $tra
     '@language' => $languages[$langcode]->name,
     '@label' => $entity->label(),
   );
-  watchdog('example', 'The @language translation of @label has just been deleted.', $variables);
+  \Drupal::logger('example')->notice('The @language translation of @label has just been deleted.', $variables);
 }
 
 /**
diff --git a/core/modules/system/src/Tests/System/SettingsRewriteTest.php b/core/modules/system/src/Tests/System/SettingsRewriteTest.php
index 5ea0bdac2f56..193371a4e7d8 100644
--- a/core/modules/system/src/Tests/System/SettingsRewriteTest.php
+++ b/core/modules/system/src/Tests/System/SettingsRewriteTest.php
@@ -8,12 +8,12 @@
 namespace Drupal\system\Tests\System;
 
 use Drupal\Core\Site\Settings;
-use Drupal\simpletest\UnitTestBase;
+use Drupal\simpletest\KernelTestBase;
 
 /**
  * Tests the drupal_rewrite_settings() function.
  */
-class SettingsRewriteTest extends UnitTestBase {
+class SettingsRewriteTest extends KernelTestBase {
   public static function getInfo() {
     return array(
       'name' => 'drupal_rewrite_settings()',
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 6cfd11fefcf7..c96de7997dfc 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -1107,16 +1107,17 @@ function system_check_directory($form_element) {
     return $form_element;
   }
 
+  $logger = \Drupal::logger('file system');
   if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
     // If the directory does not exists and cannot be created.
     form_set_error($form_element['#parents'][0], $form_state, t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));
-    watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR);
+    $logger->error('The directory %directory does not exist and could not be created.', array('%directory' => $directory));
   }
 
   if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) {
     // If the directory is not writable and cannot be made so.
     form_set_error($form_element['#parents'][0], $form_state, t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory)));
-    watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR);
+    $logger->error('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory));
   }
   elseif (is_dir($directory)) {
     if ($form_element['#name'] == 'file_public_path') {
diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module
index cd5d1edabb14..b786a676c155 100644
--- a/core/modules/tracker/tracker.module
+++ b/core/modules/tracker/tracker.module
@@ -110,7 +110,7 @@ function tracker_cron() {
       // Prepare a starting point for the next run.
       $state->set('tracker.index_nid', $last_nid - 1);
 
-      watchdog('tracker', 'Indexed %count content items for tracking.', array('%count' => $count));
+      \Drupal::logger('tracker')->notice('Indexed %count content items for tracking.', array('%count' => $count));
     }
     else {
       // If all nodes have been indexed, set to zero to skip future cron runs.
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 5e072cbbf015..8ee4265411ca 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -774,7 +774,7 @@ function user_authenticate($name, $password) {
 function user_login_finalize(UserInterface $account) {
   global $user;
   $user = $account;
-  watchdog('user', 'Session opened for %name.', array('%name' => $account->getUsername()));
+  \Drupal::logger('user')->notice('Session opened for %name.', array('%name' => $account->getUsername()));
   // Update the user table timestamp noting user has logged in.
   // This is also used to invalidate one-time login links.
   $account->setLastLoginTime(REQUEST_TIME);
@@ -906,7 +906,7 @@ function user_cancel($edit, $uid, $method) {
 
   if (!$account) {
     drupal_set_message(t('The user account %id does not exist.', array('%id' => $uid)), 'error');
-    watchdog('user', 'Attempted to cancel non-existing user account: %id.', array('%id' => $uid), WATCHDOG_ERROR);
+    \Drupal::logger('user')->error('Attempted to cancel non-existing user account: %id.', array('%id' => $uid));
     return;
   }
 
@@ -956,6 +956,7 @@ function user_cancel($edit, $uid, $method) {
  */
 function _user_cancel($edit, $account, $method) {
   global $user;
+  $logger = \Drupal::logger('user');
 
   switch ($method) {
     case 'user_cancel_block':
@@ -968,7 +969,7 @@ function _user_cancel($edit, $account, $method) {
       $account->block();
       $account->save();
       drupal_set_message(t('%name has been disabled.', array('%name' => $account->getUsername())));
-      watchdog('user', 'Blocked user: %name %email.', array('%name' => $account->getUsername(), '%email' => '<' . $account->getEmail() . '>'), WATCHDOG_NOTICE);
+      $logger->notice('Blocked user: %name %email.', array('%name' => $account->getUsername(), '%email' => '<' . $account->getEmail() . '>'));
       break;
 
     case 'user_cancel_reassign':
@@ -979,7 +980,7 @@ function _user_cancel($edit, $account, $method) {
       }
       $account->delete();
       drupal_set_message(t('%name has been deleted.', array('%name' => $account->getUsername())));
-      watchdog('user', 'Deleted user: %name %email.', array('%name' => $account->getUsername(), '%email' => '<' . $account->getEmail() . '>'), WATCHDOG_NOTICE);
+      $logger->notice('Deleted user: %name %email.', array('%name' => $account->getUsername(), '%email' => '<' . $account->getEmail() . '>'));
       break;
   }
 
@@ -1686,7 +1687,7 @@ function user_toolbar() {
 function user_logout() {
   $user = \Drupal::currentUser();
 
-  watchdog('user', 'Session closed for %name.', array('%name' => $user->getUsername()));
+  \Drupal::logger('user')->notice('Session closed for %name.', array('%name' => $user->getUsername()));
 
   \Drupal::moduleHandler()->invokeAll('user_logout', array($user));
 
diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc
index b276e57be998..e9970d71e4d2 100644
--- a/core/modules/user/user.pages.inc
+++ b/core/modules/user/user.pages.inc
@@ -60,7 +60,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
           // user_login_finalize() also updates the login timestamp of the
           // user, which invalidates further use of the one-time login link.
           user_login_finalize($account);
-          watchdog('user', 'User %name used one-time login link at time %timestamp.', array('%name' => $account->getUsername(), '%timestamp' => $timestamp));
+          \Drupal::logger('user')->notice('User %name used one-time login link at time %timestamp.', array('%name' => $account->getUsername(), '%timestamp' => $timestamp));
           drupal_set_message(t('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.'));
           // Let the user's password be changed without the current password check.
           $token = Crypt::randomBytesBase64(55);
diff --git a/core/update.php b/core/update.php
index 9147e9ef85f2..c7122d0035d6 100644
--- a/core/update.php
+++ b/core/update.php
@@ -226,7 +226,7 @@ function update_info_page() {
 function update_access_denied_page() {
   drupal_add_http_header('Status', '403 Forbidden');
   header(\Drupal::request()->server->get('SERVER_PROTOCOL') . ' 403 Forbidden');
-  watchdog('access denied', 'update.php', array(), WATCHDOG_WARNING);
+  \Drupal::logger('access denied')->warning('update.php');
   $output = '<p>Access denied. You are not authorized to access this page. Log in using either an account with the <em>administer software updates</em> permission or the site maintenance account (the account you created during installation). If you cannot log in, you will have to edit <code>settings.php</code> to bypass this access check. To do this:</p>
 <ol>
  <li>With a text editor find the settings.php file on your system. From the main Drupal directory that you installed all the files into, go to <code>sites/your_site_name</code> if such directory exists, or else to <code>sites/default</code> which applies otherwise.</li>
-- 
GitLab