mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-31 02:10:22 +02:00
Added user_agent to the WebProcessor (#1613)
This commit is contained in:
@@ -36,11 +36,12 @@ class WebProcessor implements ProcessorInterface
|
||||
'http_method' => 'REQUEST_METHOD',
|
||||
'server' => 'SERVER_NAME',
|
||||
'referrer' => 'HTTP_REFERER',
|
||||
'user_agent' => 'HTTP_USER_AGENT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|\ArrayAccess<string, mixed>|null $serverData Array or object w/ ArrayAccess that provides access to the $_SERVER data
|
||||
* @param array<string, string>|null $extraFields Field names and the related key inside $serverData to be added. If not provided it defaults to: url, ip, http_method, server, referrer
|
||||
* @param array<string, string>|array<string>|null $extraFields Field names and the related key inside $serverData to be added (or just a list of field names to use the default configured $serverData mapping). If not provided it defaults to: [url, ip, http_method, server, referrer] + unique_id if present in server data
|
||||
*/
|
||||
public function __construct($serverData = null, array $extraFields = null)
|
||||
{
|
||||
@@ -52,20 +53,23 @@ class WebProcessor implements ProcessorInterface
|
||||
throw new \UnexpectedValueException('$serverData must be an array or object implementing ArrayAccess.');
|
||||
}
|
||||
|
||||
$defaultEnabled = ['url', 'ip', 'http_method', 'server', 'referrer'];
|
||||
if (isset($this->serverData['UNIQUE_ID'])) {
|
||||
$this->extraFields['unique_id'] = 'UNIQUE_ID';
|
||||
$defaultEnabled[] = 'unique_id';
|
||||
}
|
||||
|
||||
if (null !== $extraFields) {
|
||||
if (isset($extraFields[0])) {
|
||||
foreach (array_keys($this->extraFields) as $fieldName) {
|
||||
if (!in_array($fieldName, $extraFields)) {
|
||||
unset($this->extraFields[$fieldName]);
|
||||
}
|
||||
if (null === $extraFields) {
|
||||
$extraFields = $defaultEnabled;
|
||||
}
|
||||
if (isset($extraFields[0])) {
|
||||
foreach (array_keys($this->extraFields) as $fieldName) {
|
||||
if (!in_array($fieldName, $extraFields)) {
|
||||
unset($this->extraFields[$fieldName]);
|
||||
}
|
||||
} else {
|
||||
$this->extraFields = $extraFields;
|
||||
}
|
||||
} else {
|
||||
$this->extraFields = $extraFields;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user