Skip to content

Commit 834b4ba

Browse files
holtkampjbelien
authored andcommitted
Allow to configure log levels (#950)
* Update Chain.php Allow to configure log levels * Do use constructor for log level defaults
1 parent de8d2a9 commit 834b4ba

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Provider/Chain/Chain.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Geocoder\Provider\Provider;
2020
use Psr\Log\LoggerAwareInterface;
2121
use Psr\Log\LoggerAwareTrait;
22+
use Psr\Log\LogLevel;
2223

2324
/**
2425
* @author Markus Bachmann <[email protected]>
@@ -27,6 +28,16 @@ final class Chain implements Provider, LoggerAwareInterface
2728
{
2829
use LoggerAwareTrait;
2930

31+
/**
32+
* @var string
33+
*/
34+
private $geocodeQueryLogLevel = LogLevel::ALERT;
35+
36+
/**
37+
* @var string
38+
*/
39+
private $reverseQueryLogLevel = LogLevel::ALERT;
40+
3041
/**
3142
* @var Provider[]
3243
*/
@@ -40,6 +51,16 @@ public function __construct(array $providers = [])
4051
$this->providers = $providers;
4152
}
4253

54+
public function setGeocodeQueryLogLevel(string $level)
55+
{
56+
$this->geocodeQueryLogLevel = $level;
57+
}
58+
59+
public function setReverseQueryLogLevel(string $level)
60+
{
61+
$this->reverseQueryLogLevel = $level;
62+
}
63+
4364
/**
4465
* {@inheritdoc}
4566
*/
@@ -54,7 +75,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
5475
}
5576
} catch (\Throwable $e) {
5677
$this->log(
57-
'alert',
78+
$this->geocodeQueryLogLevel,
5879
'Provider "{providerName}" could not geocode address: "{address}".',
5980
[
6081
'exception' => $e,
@@ -83,7 +104,7 @@ public function reverseQuery(ReverseQuery $query): Collection
83104
} catch (\Throwable $e) {
84105
$coordinates = $query->getCoordinates();
85106
$this->log(
86-
'alert',
107+
$this->reverseQueryLogLevel,
87108
sprintf('Provider "%s" could reverse coordinates: %f, %f.', $provider->getName(), $coordinates->getLatitude(), $coordinates->getLongitude()),
88109
['exception' => $e]
89110
);

0 commit comments

Comments
 (0)