WebformSubmissionLogLogger.php in Webform 6.x
File
modules/webform_submission_log/src/WebformSubmissionLogLogger.php
View source
<?php
namespace Drupal\webform_submission_log;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Core\Logger\RfcLoggerTrait;
use Psr\Log\LoggerInterface;
class WebformSubmissionLogLogger implements LoggerInterface {
use RfcLoggerTrait;
protected $logManager;
protected $parser;
public function __construct(LogMessageParserInterface $parser, WebformSubmissionLogManagerInterface $log_manager) {
$this->parser = $parser;
$this->logManager = $log_manager;
}
public function log($level, $message, array $context = []) {
if ($context['channel'] !== 'webform_submission') {
return;
}
if (!isset($context['webform_submission'])) {
return;
}
$webform_submission = $context['webform_submission'];
if (!$webform_submission
->getWebform()
->hasSubmissionLog()) {
return;
}
$context += [
'handler_id' => '',
'operation' => '',
'data' => [],
];
$message = (string) $message;
$message_placeholders = $this->parser
->parseMessagePlaceholders($message, $context);
$this->logManager
->insert([
'webform_id' => $webform_submission
->getWebform()
->id(),
'sid' => $webform_submission
->id(),
'handler_id' => $context['handler_id'],
'operation' => $context['operation'],
'uid' => $context['uid'],
'message' => $message,
'variables' => serialize($message_placeholders),
'data' => serialize($context['data']),
'timestamp' => $context['timestamp'],
]);
}
}