public function AcsfLog::log in Acquia Cloud Site Factory Connector 8.2
Same name and namespace in other branches
- 8 src/AcsfLog.php \Drupal\acsf\AcsfLog::log()
Logs the specified message to the Site Factory via the REST API.
Parameters
string $type: The type of log message, usually defining the source of the message.
string $message: The log message to send.
string $level: The severity of the log message. Uses the predefined syslog() constants that follow RFC 3164. Defaults to LOG_NOTICE.
int $timestamp: The Unix timestamp representing when the event occurred. Defaults to the timestamp for the current request.
int $nid: The site node ID that the message relates to. Defaults to the current site.
File
- src/
AcsfLog.php, line 29
Class
- AcsfLog
- ACSFLog.
Namespace
Drupal\acsfCode
public function log($type, $message, $level = NULL, $timestamp = NULL, $nid = NULL) {
if (empty($timestamp)) {
$timestamp = \Drupal::time()
->getRequestTime();
}
if (empty($type) || empty($message)) {
throw new \RuntimeException('Missing required parameter.');
}
if (!$this
->enabled()) {
return;
}
if (empty($nid)) {
$site = AcsfSite::load();
$nid = $site->site_id;
}
$record = [
'type' => $type,
'message' => $message,
'level' => $level ?: LOG_NOTICE,
'timestamp' => $timestamp,
'nid' => $nid,
];
try {
$message = new AcsfMessageRest('POST', 'site-api/v1/sf-log', $record);
$message
->send();
return $message
->getResponseBody();
} catch (\Exception $e) {
// Swallow exceptions.
}
}