onramplab/laravel-log-enhancement
laravel-log-enhancement
A library with logging enhancement. Including:
-
Overriding
Logfacade- It extends default Laravel
Logfacade with logging adding class path and tracking id into context.
- It extends default Laravel
-
LogglyHandlerclass- It extends monolog's LogglyHandler with tags support
-
DatadogHandlerclass- 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
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
637,827,751
9,703
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
413,412,504
609
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
394,964,158
4,660
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v12.0.2 | ^8.2 | ^11.0| | MIT | |
| v12.0.1 | ^8.2 | ^11.0| | MIT | |
| v12.0.0 | ^8.2 | ^11.0| | MIT | |
| v10.0.2 | >=8.1 | * | MIT | |
| v10.0.1 | >=7.3 | * | MIT | |
| v10.0.0 | >=7.3 | * | MIT | |
| v8.2.2 | >=7.3 | MIT | ||
| v8.2.1 | >=7.3 | MIT | ||
| v8.2.0 | >=7.3 | MIT | ||
| v8.1.1 | >=7.3 | MIT | ||
| v8.1.0 | >=7.3 | MIT | ||
| v8.0.0 | >=7.3 | MIT | ||
| v7.0.0 | >=7.2 | MIT | ||
| v1.1.0 | MIT | |||
| v1.0.0 | MIT | |||
| v0.4.2 | MIT | |||
| v0.4.1 | MIT | |||
| v0.4.0 | MIT | |||
| v0.3.0 | MIT | |||
| v0.2.0 | MIT | |||
| v0.1.0 | MIT |