naresh / eslogger
ElasticSearch logging library for laravel 5.6
Requires
- php: >=7.0
- aws/aws-sdk-php: ^3.8
- guzzlehttp/guzzle: ~6.0
- naresh/elasticsearchclient: 1.0.*
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ~3.0
- phpunit/phpunit: ^6.2.3
This package is auto-updated.
Last update: 2024-09-14 22:14:13 UTC
README
Note: You can use Molong Elasticsearch Handler to achieve same behaviour as this library. However it only supports Elastica client.
If you want to use Elasticsearch logging channel for logging(Laravel >=5.6) then this library is for you.
Installation
Require package in composer.json file.
"require":{
"naresh/eslogger": "1.0.*"
}
And run composer update to update the dependency.
Configuration
Add Elasticsearch logger in your
config/logging.php
'channels' => [ 'custom' => [ 'driver' => 'custom', 'via' => \Naresh\ElasticSearchLogger\EsLog::class, ], ],
Add Elasticsearch configuration
Option 1 Configure with ENV variables
ES_HOST
- Elasticsearch host
IS_AWS_ES_HOST
- Boolean flag to specify if the hostname is AWS Elasticsearch service, however if your host has
amazonaws
in its URL then you dont have to add this flag, this library will assume it as AWS Elasticsearch service
- Boolean flag to specify if the hostname is AWS Elasticsearch service, however if your host has
AWS_ACCESS_KEY_ID(only needed if host is AWS Elasticsearch service)
- AWS Elasticsearch service access key
AWS_SECRET_ACCESS_KEY(only needed if host is AWS Elasticsearch service)
- AWS Elasticsearch service secret key
AWS_REGION(only needed if host is AWS Elasticsearch service)
- AWS Elasticsearch service region
ES_LOG_INDEX
- Elasticsearch Index where you want to send the logs
ES_LOG_INDEX_TYPE
- Elasticsearch Index type
Option 2 If you do not want to use ENV variables then you can configure it while setting it in the
config/logging.php
file.- By creating new instance
- Create a new instance of
\Naresh\ElasticSearchLogger\EsLog
like following$eslogger = new \Naresh\ElasticSearchLogger\EsLog();
- Then pass the configurations to the
EsLog
instance,'channels' => [ 'custom' => [ 'driver' => 'custom', 'via' => $esLogger(['options' => ['ES_HOST' => 'test.es.com']]), ], ],
- Create a new instance of
- By passing options in logging configuration
'channels' => [ 'custom' => [ 'driver' => 'custom', 'via' => \Naresh\ElasticSearchLogger\EsLog::class, 'options' => [ "hosts" => ["test.es-server.com"], "aws_host" => "", "access_key" => "LK9823kjhsd", "secret_key" => "LK9823kjhsd", "region" => "ap-southeast-2", "index" => "testIndex", "index_type" => "testIndexType"] ], ],
- By creating new instance