1[[enabling_logger]]
2=== Enabling the Logger
3
4Elasticsearch-PHP supports logging, but it is not enabled by default for
5performance reasons. If you wish to enable logging, you need to select a logging
6implementation, install it, then enable the logger in the Client. The
7recommended logger is https://github.com/Seldaek/monolog[Monolog], but any
8logger that implements the `PSR/Log` interface works.
9
10You might have noticed that Monolog was suggested during installation. To begin
11using Monolog, add it to your `composer.json`:
12
13[source,json]
14----------------------------
15{
16    "require": {
17        ...
18        "elasticsearch/elasticsearch" : "~5.0",
19        "monolog/monolog": "~1.0"
20    }
21}
22----------------------------
23
24And then update your Composer installation:
25
26[source,shell]
27----------------------------
28php composer.phar update
29----------------------------
30
31Once Monolog (or another logger) is installed, you need to create a log object
32and inject it into the client:
33
34[source,php]
35----
36use Monolog\Logger;
37use Monolog\Handler\StreamHandler;
38
39$logger = new Logger('name');
40$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
41
42$client = ClientBuilder::create()       // Instantiate a new ClientBuilder
43            ->setLogger($logger)        // Set your custom logger
44            ->build();                  // Build the client object
45----