/**
* Format a line for the log file.
*
* @param LogEntry $entry The log entry to format as a string.
*
* @return String
*
* @since 3.9.0
*/
protected function formatLine(LogEntry $entry)
{
// Set some default field values if not already set.
if (!isset($entry->clientIP)) {
$ip = IpHelper::getIp();
if ($ip !== '') {
$entry->clientIP = $ip;
}
}
// If the time field is missing or the date field isn't only the date we need to rework it.
if (\strlen($entry->date) != 10 || !isset($entry->time)) {
// Get the date and time strings in GMT.
$entry->datetime = $entry->date->toISO8601();
$entry->time = $entry->date->format('H:i:s', false);
$entry->date = $entry->date->format('Y-m-d', false);
}
// Get a list of all the entry keys and make sure they are upper case.
$tmp = array_change_key_case(get_object_vars($entry), CASE_UPPER);
// Decode the entry priority into an English string.
$tmp['PRIORITY'] = $this->priorities[$entry->priority];
// Fill in field data for the line.
$line = $this->format;
foreach ($this->fields as $field) {
$line = str_replace('{' . $field . '}', $tmp[$field] ?? '-', $line);
}
return $line;
}