Skip to content

Support class-based logObject resolution in logging #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: mailerlite
github: anashaat
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
An easy way to use the [official Elastic Search client](https://github.com/elastic/elasticsearch-php) in your Laravel or Lumen applications.

[![Build Status](https://github.com/mailerlite/laravel-elasticsearch/workflows/tests/badge.svg?branch=master)](https://github.com/mailerlite/laravel-elasticsearch/actions)
[![Total Downloads](https://poser.pugx.org/mailerlite/laravel-elasticsearch/downloads.png)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)
[![Latest Stable Version](https://poser.pugx.org/mailerlite/laravel-elasticsearch/v/stable.png)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)
[![Latest Stable Version](https://poser.pugx.org/mailerlite/laravel-elasticsearch/v/unstable.png)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)
[![Total Downloads](https://poser.pugx.org/mailerlite/laravel-elasticsearch/downloads.png)](https://packagist.org/packages/anashaat/laravel-elasticsearch)
[![Latest Stable Version](https://poser.pugx.org/mailerlite/laravel-elasticsearch/v/stable.png)](https://packagist.org/packages/anashaat/laravel-elasticsearch)
[![Latest Stable Version](https://poser.pugx.org/mailerlite/laravel-elasticsearch/v/unstable.png)](https://packagist.org/packages/anashaat/laravel-elasticsearch)
[![License](https://img.shields.io/packagist/l/mailerlite/laravel-elasticsearch)](LICENSE.md)


Expand All @@ -25,10 +25,10 @@ An easy way to use the [official Elastic Search client](https://github.com/elast

## Installation and Configuration

Install the current version of the `mailerlite/laravel-elasticsearch` package via composer:
Install the current version of the `anashaat/laravel-elasticsearch` package via composer:

```sh
composer require mailerlite/laravel-elasticsearch
composer require anashaat/laravel-elasticsearch
```

If you are using ElasticSearch version 5, then install version 2 of this package:
Expand Down Expand Up @@ -150,6 +150,19 @@ If you are using `php artisan config:cache`, you cannot have the Closure in your
],
```

#### Logging Configuration

- **Custom Logger Support**: You can now define `logObject` in the configuration using a class reference (e.g., `\App\Logging\ElasticsearchLogger::class`).
- **Automatic Resolution**: If `logObject` is a class reference, it will be resolved via `app($logObject)`.
- **Alternative Logging**: If no logger is provided, but `logPath` and `logLevel` are set, a default `StreamHandler` logger will be created.
- **Example Usage**:

```php
'logObject' => \App\Logging\ElasticsearchLogger::class,
```

This allows for greater flexibility in managing Elasticsearch logs.

### Lumen

If you work with Lumen, please register the service provider and configuration in `bootstrap/app.php`:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "mailerlite/laravel-elasticsearch",
"name": "anashaat/laravel-elasticsearch",
"description": "An easy way to use the official PHP ElasticSearch client in your Laravel applications.",
"keywords": [
"laravel",
"elasticsearch",
"search",
"client"
],
"homepage": "https://github.com/mailerlite/laravel-elasticsearch",
"homepage": "https://github.com/AbdElrahmaN31/laravel-elasticsearch",
"license": "MIT",
"authors": [
{
"name": "MailerLite",
"email": "info@mailerlite.com"
"name": "ANashaat",
"email": "abdelrahmanndev@gmail.com"
}
],
"require": {
"php": "^7.3|^8.0",
"php": "^7.3|^8.0|^8.1",
"ext-json": "*",
"elasticsearch/elasticsearch": "^7.11",
"guzzlehttp/psr7": "^1.7|^2.0",
Expand Down Expand Up @@ -62,7 +62,7 @@
}
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"sort-packages": true
Expand Down
2 changes: 2 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protected function buildClient(array $config): Client
$logLevel = Arr::get($config, 'logLevel');
if ($logObject && $logObject instanceof LoggerInterface) {
$clientBuilder->setLogger($logObject);
} elseif ($logObject && app($logObject) instanceof LoggerInterface) {
$clientBuilder->setLogger(app($logObject));
} elseif ($logPath && $logLevel) {
$handler = new StreamHandler($logPath, $logLevel);
$logObject = new Logger('log');
Expand Down