public function JsonLog::prepareLog in JSONlog 8
Same name and namespace in other branches
- 8.2 src/Logger/JsonLog.php \Drupal\jsonlog\Logger\JsonLog::prepareLog()
- 3.x src/Logger/JsonLog.php \Drupal\jsonlog\Logger\JsonLog::prepareLog()
Setup the log entry if necessary
Parameters
int $level:
string $message:
array $context:
Return value
\Drupal\jsonlog\Logger\JsonLogData | bool FALSE
1 call to JsonLog::prepareLog()
- JsonLog::log in src/
Logger/ JsonLog.php - Logs any log statement - at or above a certain severity threshold - to a custom log file as JSON.
File
- src/
Logger/ JsonLog.php, line 144
Class
- JsonLog
- Redirects logging messages to jsonlog.
Namespace
Drupal\jsonlog\LoggerCode
public function prepareLog($level, $message, array $context = []) {
// Severity is upside down; less is more. Do not log below configured
// threshold.
if ($level > $this->threshold || empty($context)) {
return FALSE;
}
// Populate the message placeholders and then replace them in the message.
$variables = $this->parser
->parseMessagePlaceholders($message, $context);
// Determine HTTP method in case we are dealing with a valid request context
$method = empty($context['request_uri']) ? '' : $this->requestStack
->getCurrentRequest()
->getRealMethod();
// Create the entry.
$entry = new JsonLogData($this->site_id, $this->canonical);
$entry
->setTags($this->tags_server, $this->tags_site);
$entry
->setMessage($message, $this->truncate, $variables);
$entry
->setSeverity($level);
$entry
->setSubType($context['channel']);
$entry
->setMethod($method);
$entry
->setRequest_uri($context['request_uri']);
$entry
->setReferer($context['referer']);
$entry
->setAccount(isset($context['user']) ? $context['user'] : NULL);
$entry
->setClient_ip($context['ip']);
$entry
->setLink($context['link']);
return $entry;
}