1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-03 19:57:41 +02:00

Added user_agent to the WebProcessor (#1613)

This commit is contained in:
Alex Jose
2022-03-06 17:57:57 +05:30
committed by GitHub
parent 030c25c4d2
commit 5129feea3e

View File

@@ -36,11 +36,12 @@ class WebProcessor implements ProcessorInterface
'http_method' => 'REQUEST_METHOD', 'http_method' => 'REQUEST_METHOD',
'server' => 'SERVER_NAME', 'server' => 'SERVER_NAME',
'referrer' => 'HTTP_REFERER', '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, 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) 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.'); 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'])) { if (isset($this->serverData['UNIQUE_ID'])) {
$this->extraFields['unique_id'] = 'UNIQUE_ID'; $this->extraFields['unique_id'] = 'UNIQUE_ID';
$defaultEnabled[] = 'unique_id';
} }
if (null !== $extraFields) { if (null === $extraFields) {
if (isset($extraFields[0])) { $extraFields = $defaultEnabled;
foreach (array_keys($this->extraFields) as $fieldName) { }
if (!in_array($fieldName, $extraFields)) { if (isset($extraFields[0])) {
unset($this->extraFields[$fieldName]); foreach (array_keys($this->extraFields) as $fieldName) {
} if (!in_array($fieldName, $extraFields)) {
unset($this->extraFields[$fieldName]);
} }
} else {
$this->extraFields = $extraFields;
} }
} else {
$this->extraFields = $extraFields;
} }
} }