class WebformSubmissionLogLogger in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_submission_log/src/WebformSubmissionLogLogger.php \Drupal\webform_submission_log\WebformSubmissionLogLogger
Logger that listens for 'webform_submission' channel.
Hierarchy
- class \Drupal\webform_submission_log\WebformSubmissionLogLogger implements \Psr\Log\LoggerInterface uses RfcLoggerTrait
Expanded class hierarchy of WebformSubmissionLogLogger
1 string reference to 'WebformSubmissionLogLogger'
- webform_submission_log.services.yml in modules/
webform_submission_log/ webform_submission_log.services.yml - modules/webform_submission_log/webform_submission_log.services.yml
1 service uses WebformSubmissionLogLogger
- logger.webform_submission_log in modules/
webform_submission_log/ webform_submission_log.services.yml - Drupal\webform_submission_log\WebformSubmissionLogLogger
File
- modules/
webform_submission_log/ src/ WebformSubmissionLogLogger.php, line 12
Namespace
Drupal\webform_submission_logView source
class WebformSubmissionLogLogger implements LoggerInterface {
use RfcLoggerTrait;
/**
* The webform submission log manager.
*
* @var \Drupal\webform_submission_log\WebformSubmissionLogManagerInterface
*/
protected $logManager;
/**
* The message's placeholders parser.
*
* @var \Drupal\Core\Logger\LogMessageParserInterface
*/
protected $parser;
/**
* WebformSubmissionLog constructor.
*
* @param \Drupal\Core\Logger\LogMessageParserInterface $parser
* The log message parser service.
* @param \Drupal\webform_submission_log\WebformSubmissionLogManagerInterface $log_manager
* The webform submission log manager.
*/
public function __construct(LogMessageParserInterface $parser, WebformSubmissionLogManagerInterface $log_manager) {
$this->parser = $parser;
$this->logManager = $log_manager;
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []) {
// Only log the 'webform_submission' channel.
if ($context['channel'] !== 'webform_submission') {
return;
}
// Make sure the context contains a webform submission.
if (!isset($context['webform_submission'])) {
return;
}
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $context['webform_submission'];
// Make sure webform submission log is enabled.
if (!$webform_submission
->getWebform()
->hasSubmissionLog()) {
return;
}
// Set default values.
$context += [
'handler_id' => '',
'operation' => '',
'data' => [],
];
// Cast message to string.
$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'],
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
WebformSubmissionLogLogger:: |
protected | property | The webform submission log manager. | |
WebformSubmissionLogLogger:: |
protected | property | The message's placeholders parser. | |
WebformSubmissionLogLogger:: |
public | function |
Logs with an arbitrary level. Overrides RfcLoggerTrait:: |
|
WebformSubmissionLogLogger:: |
public | function | WebformSubmissionLog constructor. |