onramplab / laravel-log-enhancement
An enhanced logging package for Laravel
Installs: 24 015
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 1
Open Issues: 2
Requires
- php: >=8.1
- datadog/dd-trace: ^0.90.0
- illuminate/contracts: *
- illuminate/log: *
- illuminate/support: *
- monolog/monolog: ^3.4
- ramsey/uuid: ^4.0.0
Requires (Dev)
- fakerphp/faker: ^1.23
- mockery/mockery: ^1.3.2
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^8.10
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- symfony/thanks: ^1.0
This package is auto-updated.
Last update: 2024-11-08 04:22:35 UTC
README
A library with logging enhancement. Including:
-
Overriding
Log
facade- It extends default Laravel
Log
facade with logging adding class path and tracking id into context.
- It extends default Laravel
-
LogglyHandler
class- It extends monolog's LogglyHandler with tags support
-
DatadogHandler
class- It supports Datadog Logs
Install
composer require onramplab/laravel-log-enhancement
- use Datadog APM to connect php logs and traces
curl -LO https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php sudo php datadog-setup.php --php-bin=all
Usage
LoggerFacade
The log json will look like this:
{ "message": "Test", "context": { "class_path": "App\\Fake", "tracking_id": "652c3456-1a17-42b8-9fa7-9bee65e655eb" }, "level": 200, "level_name": "INFO", "channel": "local", "extra": {}, "timestamp": "2021-01-04T22:47:56.598608-0800" }
LogglyHandler
You can adding following block into config/logging.php
.
use Monolog\Formatter\LogglyFormatter; use Onramplab\LaravelLogEnhancement\Handlers\LogglyHandler; return [ //... 'channels' => [ //... 'loggly' => [ 'driver' => 'monolog', 'level' => 'info', 'handler' => LogglyHandler::class, 'handler_with' => [ 'token' => env('LOGGLY_TOKEN'), 'tags' => env('LOGGLY_TAGS'), ], 'formatter' => LogglyFormatter::class, ], ] ];
DatadogHandler
You can adding following block into config/logging.php
.
use Monolog\Formatter\JsonFormatter; use Onramplab\LaravelLogEnhancement\Handlers\DatadogHandler; return [ //... 'channels' => [ //... 'datadog' => [ 'driver' => 'monolog', 'level' => 'info', 'handler' => DatadogHandler::class, 'handler_with' => [ 'key' => env('DD_LOG_API_KEY'), 'region' => env('DD_LOG_REGION', 'us5'), 'attributes' => [ 'hostname' => gethostname(), 'source' => env('DD_LOG_SOURCE', 'laravel'), 'service' => env('DD_LOG_SERVICE'), 'tags' => env('DD_LOG_TAG'), ], ], 'formatter' => JsonFormatter::class, ], ] ];
Testing
Run the tests with:
vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email kos.huang@onramplab.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.# laravel-log-enhancement