Currently I am sending laravel logs to elasticsearch via filebeat and logstash, Is is possible to send laravel logs directly to elasticsearch without filbeat and logstash.
Asked
Active
Viewed 2,150 times
0
-
I explained the details of such an implementations here: https://stackoverflow.com/questions/67785985/how-to-use-monolog-elasticsearchhandler-for-logging-in-a-laravel-application/67785986#67785986 – Max Shaian Jun 17 '21 at 11:05
1 Answers
1
You can do this with the ElasticsearchHandler of Monolog.
See https://laravel.com/docs/8.x/logging#creating-custom-channels-via-factories how to create a custom log channel via factories.
composer require elasticsearch/elasticsearch
Something like this in your factory:
public function __invoke(array $config)
{
return new \Monolog\Logger(
$config['name'] ?? 'defaultChannelName',
[
new \Monolog\Handler\ElasticsearchHandler(
// ...
// see phpdoc of the ElasticsearchHandler::class
)
]
);
}

RiWe
- 367
- 3
- 9