geocoder-php/GeocoderLaravel

Inject Logger configuration

simonschaufi opened this issue · 2 comments

General Information

GeocoderLaravel Version: any
Laravel Version: 5.6
PHP Version: any
Operating System and Version: any

Issue Description

I would like to log Exceptions during geocoding but don't know how to configure my logger. I already asked how to use the logger in Geocoder package and got an answer: geocoder-php/Geocoder#901 (comment). What is missing is any kind of configuration to use the Laravel Logger

Steps to Replicate

  1. Do a geocoding which will throw an exception (for example invalid API key)
  2. In many places the internal logger interface is called like $this->log()
  3. Write this log message to a file

Hi, Laravel not supported automatic setters.

You can create PR and insert Logger to ProviderAndDumperAggregator

$this->aggregator->registerProvider($provider);

Here is example like can do this (I didn't testing this solution):

$this->aggregator->registerProvider($provider);
if (in_array('Psr\Log\LoggerAwareTrait', class_uses($provider) && app('Illuminate\Log\Logger') !== null) {
   $provider->setLogger(app('Illuminate\Log\Logger'))
}

I hope this help you.

I tried debugging the whole process and this method got never called.

This is my config:

    'providers' => [
        Chain::class => [
            GoogleMaps::class => [
                env('GOOGLEMAPS_LOCALE', 'de-DE'),
                env('GOOGLEMAPS_APIKEY_SERVER'),
            ],
            Nominatim::class => [
                'https://nominatim.openstreetmap.org',
                'info@example.com',
            ],
        ],
    ],

and in my App I call:

$query = '<The address to be geocoded>';
$geoCoder = app('geocoder');
$addresses = $geoCoder->geocode($query)->get();

I would highly appreciate it if you could send me a working solution with the logger running.