This package adds ECS (Elastic Common Scheme) format to your laravel application allowing to log your standard logs to elastic.
You can install the package via composer:
composer require aviationcode/laravel-ecs-logging
It's recommended to require jenssegers/agent
which will add user agent logging support.
composer require jenssegers/agent
Optionally, you can publish the config file with:
php artisan vendor:publish --provider="AviationCode\EcsLogging\EcsLoggingServiceProvider" --tag="config"
Register log driver in config/logging.php
return [
'channels' => [
// ... Other channels
'ecs' => [
'driver' => 'ecs',
'path' => storage_path('logs/ecs/laravel.json'),
'level' => 'debug',
'days' => 14,
],
]
];
If you want to use this driver as the only logging method define LOG_CHANNEL=ecs
in your .env
or add the ecs
channel into your stack driver.
All Log::xxx()
calls get logged into json file. This file can be picked up by filebeat which sends it to your logstash or elasticsearch instance.
Add the following to your /etc/filebeat/filebeat.yml
file
filebeat.inputs:
- type: log
enabled: true
paths:
- /path-to-your-laravel-app/storage/logs/ecs/*.json
json:
message_key: message
keys_under_root: true
overwrite_keys: true
Event defines something that happened, this could be a single point in time or lasting a certain period. In order to log an event you can add this log context.
Log::info('Password changed for John Doe<[email protected]>', [
'event' => [
'action' => 'user-password-change',
'code' => 4648,
'outcome' => \AviationCode\EcsLogging\Types\Event::OUTCOME_SUCCESS,
'type' => 'user',
],
]);
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.