sec-dojo-com / laravel-ecs-logging
Adding ECS (Elastic Common Schema) Logging to Laravel (Updated).
Installs: 2 322
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- ext-json: *
- illuminate/support: ^8.0
Requires (Dev)
- jenssegers/agent: ^2.6
- orchestra/testbench: ^v6.0
- phpcompatibility/php-compatibility: ^9.3
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
Suggests
- jenssegers/agent: ^2.6
This package is auto-updated.
Last update: 2025-03-14 20:46:35 UTC
README
This package adds ECS (Elastic Common Scheme) format to your laravel application allowing to log your standard logs to elastic.
Installation
You can install the package via composer:
composer require sec-dojo-com/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.
Configure filebeat
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
Bugs:
Current bugs within the ecs-logs package:
Typed static property Aviation Code\Ecs Logging\Tracing\Correlate::$id must not be accessed before initialization
. This is due to trying to access type hinted properties statically before assigning values to them, this was fixed by initialising them with null values.
Original repository
This package is a fork of AviationCode\EcsLogging. With updates and bug fixes.
Fork Changelog:
13/05/2022:
Added the option to disable log file rotation through config file (Use the option disable_rotate
)
Credits
License
The MIT License (MIT). Please see License File for more information.