comparison core/modules/dblog/src/Logger/DbLog.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
1 <?php 1 <?php
2 2
3 namespace Drupal\dblog\Logger; 3 namespace Drupal\dblog\Logger;
4 4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Database\Connection; 5 use Drupal\Core\Database\Connection;
7 use Drupal\Core\Database\Database; 6 use Drupal\Core\Database\Database;
8 use Drupal\Core\Database\DatabaseException; 7 use Drupal\Core\Database\DatabaseException;
9 use Drupal\Core\DependencyInjection\DependencySerializationTrait; 8 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
10 use Drupal\Core\Logger\LogMessageParserInterface; 9 use Drupal\Core\Logger\LogMessageParserInterface;
55 */ 54 */
56 public function log($level, $message, array $context = []) { 55 public function log($level, $message, array $context = []) {
57 // Remove any backtraces since they may contain an unserializable variable. 56 // Remove any backtraces since they may contain an unserializable variable.
58 unset($context['backtrace']); 57 unset($context['backtrace']);
59 58
60 // Convert PSR3-style messages to SafeMarkup::format() style, so they can be 59 // Convert PSR3-style messages to \Drupal\Component\Render\FormattableMarkup
61 // translated too in runtime. 60 // style, so they can be translated too in runtime.
62 $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context); 61 $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
63 62
64 try { 63 try {
65 $this->connection 64 $this->connection
66 ->insert('watchdog') 65 ->insert('watchdog')
67 ->fields([ 66 ->fields([
68 'uid' => $context['uid'], 67 'uid' => $context['uid'],
69 'type' => Unicode::substr($context['channel'], 0, 64), 68 'type' => mb_substr($context['channel'], 0, 64),
70 'message' => $message, 69 'message' => $message,
71 'variables' => serialize($message_placeholders), 70 'variables' => serialize($message_placeholders),
72 'severity' => $level, 71 'severity' => $level,
73 'link' => $context['link'], 72 'link' => $context['link'],
74 'location' => $context['request_uri'], 73 'location' => $context['request_uri'],
75 'referer' => $context['referer'], 74 'referer' => $context['referer'],
76 'hostname' => Unicode::substr($context['ip'], 0, 128), 75 'hostname' => mb_substr($context['ip'], 0, 128),
77 'timestamp' => $context['timestamp'], 76 'timestamp' => $context['timestamp'],
78 ]) 77 ])
79 ->execute(); 78 ->execute();
80 } 79 }
81 catch (\Exception $e) { 80 catch (\Exception $e) {