<?php

namespace Buckhill\LogMe\Provider;

use Elasticsearch\ClientBuilder;
use Illuminate\Support\ServiceProvider;

class ElasticSearchClient extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton('ElasticSearchClient', function($app)
        {
            $client = ClientBuilder::create()
                    ->setHosts(config('logme.hosts'))
                    ->setRetries(config('logme.retries'))
                ;

            if(config('logme.log.enabled'))
            {
                $logger = ClientBuilder::defaultLogger(storage_path('logs/' . config('logme.log.filename')));

                $client->setLogger($logger);
            }

            return $client->build();
        });
    }
}
