11# laravel-log-enhancement
22
33[ ![ Software License] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square )] ( LICENSE.md )
4- [ ![ CircleCI] ( https://circleci.com/gh/OnrampLab/next-starter .svg?style=shield )] ( )
4+ [ ![ CircleCI] ( https://circleci.com/gh/OnrampLab/laravel-log-enhancement .svg?style=shield )] ( https://circleci.com/gh/OnrampLab/laravel-log-enhancement )
55[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/onramplab/laravel-log-enhancement.svg?style=flat-square )] ( https://packagist.org/packages/onramplab/laravel-log-enhancement )
66
77A library with logging enhancement. Including:
88
9- - ` LogWithClassPath ` trait
10- - It adds convinient methods for logging to add class path into context.
11- - ` LogglyHandler ` class
12- - It extends monolog's LogglyHandler with tags support
9+ - ` LoggerFacade ` facade
10+ - It extends default Laravel ` Log ` facade with logging adding class path and tracking id into context.
11+ - ` LogWithClassPath ` trait (* deprecated* )
12+ - It adds convinient methods for logging to add class path and tracking id into context.
13+ - ` LogglyHandler ` class
14+ - It extends monolog's LogglyHandler with tags support
1315
1416## Install
1517
1618``` bash
1719composer require onramplab/laravel-log-enhancement
1820```
1921
20-
2122## Usage
2223
23- ### LogWithClassPath Trait
24+ ### LoggerFacade
25+
26+ Replace the class of ` Log ` alias to ` LoggerFacade ` in ` config/app.php ` as aliases.
27+
28+ ``` php
29+ 'Log' => Onramplab\LaravelLogEnhancement\Facades\LoggerFacade::class,
30+ ```
31+
32+ The log json will look like this:
33+
34+ ``` json
35+ {
36+ "message" : " Test" ,
37+ "context" : {
38+ "class_path" : " App\\ Fake" ,
39+ "tracking_id" : " 652c3456-1a17-42b8-9fa7-9bee65e655eb"
40+ },
41+ "level" : 200 ,
42+ "level_name" : " INFO" ,
43+ "channel" : " local" ,
44+ "extra" : {},
45+ "timestamp" : " 2021-01-04T22:47:56.598608-0800"
46+ }
47+ ```
48+
49+ ### LogWithClassPath Trait (* deprecated* )
50+
2451Use ` LogWithClassPath ` trait to let it automatically put class path into log context. You can refer to following code example.
2552
2653``` php
@@ -44,7 +71,8 @@ The log json will look like this:
4471{
4572 "message" : " Test" ,
4673 "context" : {
47- "class_path" : " App\\ Fake"
74+ "class_path" : " App\\ Fake" ,
75+ "tracking_id" : " 652c3456-1a17-42b8-9fa7-9bee65e655eb"
4876 },
4977 "level" : 200 ,
5078 "level_name" : " INFO" ,
@@ -84,7 +112,6 @@ return [
84112
85113```
86114
87-
88115## Testing
89116
90117Run the tests with:
@@ -93,17 +120,14 @@ Run the tests with:
93120vendor/bin/phpunit
94121```
95122
96-
97123## Contributing
98124
99125Please see [ CONTRIBUTING] ( CONTRIBUTING.md ) for details.
100126
101-
102127## Security
103128
104129If you discover any security-related issues, please email kos.huang@onramplab.com instead of using the issue tracker.
105130
106-
107131## License
108132
109133The MIT License (MIT). Please see [ License File] ( /LICENSE.md ) for more information.# laravel-log-enhancement
0 commit comments