Skip to content

Commit d0b5644

Browse files
committed
Added readme
1 parent 798e60b commit d0b5644

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

README.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Laravel Application Logger
2+
3+
![Run tests](https://github.com/kitloong/laravel-app-logger/workflows/Run%20tests/badge.svg?branch=main)
4+
[![Latest Stable Version](https://poser.pugx.org/kitloong/laravel-app-logger/v/stable.png)](https://packagist.org/packages/kitloong/laravel-app-logger)
5+
[![License](https://poser.pugx.org/kitloong/laravel-app-logger/license.png)](https://packagist.org/packages/kitloong/laravel-app-logger)
6+
7+
This package provides middleware that generate **http request** and **performance** logs for you application.
8+
9+
This package also provides Database **query log** to track all executed queries by your application.
10+
11+
## Installation
12+
13+
```bash
14+
composer require "kitloong/laravel-app-logger"
15+
```
16+
17+
## Usage
18+
19+
To start using **http request** and **performance** logger please add package's middleware in your `app/Http/Kernel.php` or routes.
20+
21+
```
22+
\KitLoong\AppLogger\Middlewares\AppLogger::class
23+
```
24+
25+
No code modification needed to use **DB query log**, you only need to enable it through `.env`.
26+
27+
## Configuration
28+
29+
By default, **Http request** and **performance** are enabled while **query log** is disabled.
30+
31+
However, you could change each setting respectively by difference environment.
32+
33+
```dotenv
34+
# By default
35+
36+
RUN_HTTP_LOG=true
37+
RUN_PERFORMANCE_LOG=true
38+
RUN_QUERY_LOG=false
39+
```
40+
41+
You could also publish config file to change more configuration or even use your own implementation
42+
43+
```bash
44+
php artisan vendor:publish --provider="KitLoong\AppLogger\AppLoggerServiceProvider" --tag=config
45+
```
46+
47+
This is content of config file
48+
49+
```
50+
[
51+
'http' => [
52+
'enabled' => env('RUN_HTTP_LOG', true),
53+
54+
/*
55+
* The log profile which determines whether a request should be logged.
56+
* It should implement `HttpLogProfile`.
57+
*/
58+
'log_profile' => \KitLoong\AppLogger\HttpLog\LogProfile::class,
59+
60+
/*
61+
* The log writer used to write the request to a log.
62+
* It should implement `HttpLogWriter`.
63+
*/
64+
'log_writer' => \KitLoong\AppLogger\HttpLog\LogWriter::class,
65+
66+
/*
67+
* If you are using default `HttpLogProfile` provided by the package,
68+
* you could define which HTTP methods should be logged.
69+
*/
70+
'should_log' => [
71+
\Illuminate\Http\Request::METHOD_POST,
72+
\Illuminate\Http\Request::METHOD_PUT,
73+
\Illuminate\Http\Request::METHOD_PATCH,
74+
\Illuminate\Http\Request::METHOD_DELETE,
75+
],
76+
77+
/*
78+
* Filter out body fields which will never be logged.
79+
*/
80+
'except' => [
81+
'password',
82+
'password_confirmation',
83+
],
84+
85+
/*
86+
* Log channel name define in config/logging.php
87+
* null value to use default channel.
88+
*/
89+
'channel' => null,
90+
],
91+
92+
'performance' => [
93+
'enabled' => env('RUN_PERFORMANCE_LOG', true),
94+
95+
/*
96+
* The log profile which determines whether a request should be logged.
97+
* It should implement `PerformanceLogProfile`.
98+
*/
99+
'log_profile' => \KitLoong\AppLogger\PerformanceLog\LogProfile::class,
100+
101+
/*
102+
* The log writer used to write the request to a log.
103+
* It should implement `PerformanceLogWriter`.
104+
*/
105+
'log_writer' => \KitLoong\AppLogger\PerformanceLog\LogWriter::class,
106+
107+
/*
108+
* If you are using default `PerformanceLogProfile` provided by the package,
109+
* you could define which HTTP methods should be logged.
110+
*/
111+
'should_log' => [
112+
\Illuminate\Http\Request::METHOD_GET,
113+
\Illuminate\Http\Request::METHOD_POST,
114+
\Illuminate\Http\Request::METHOD_PUT,
115+
\Illuminate\Http\Request::METHOD_PATCH,
116+
\Illuminate\Http\Request::METHOD_DELETE,
117+
],
118+
119+
/*
120+
* Log channel name define in config/logging.php
121+
* null value to use default channel.
122+
*/
123+
'channel' => null,
124+
],
125+
126+
'query' => [
127+
'enabled' => env('RUN_QUERY_LOG', false),
128+
129+
/*
130+
* The log profile which determines whether a request should be logged.
131+
* It should implement `QueryLogProfile`.
132+
*/
133+
'log_profile' => \KitLoong\AppLogger\QueryLog\LogProfile::class,
134+
135+
/*
136+
* The log writer used to write the request to a log.
137+
* It should implement `QueryLogWriter`.
138+
*/
139+
'log_writer' => \KitLoong\AppLogger\QueryLog\LogWriter::class,
140+
141+
/*
142+
* Log channel name define in config/logging.php
143+
* null value to use default channel.
144+
*/
145+
'channel' => null,
146+
],
147+
];
148+
```
149+
150+
This package used https://github.com/spatie/laravel-http-logger as base for **http request** log, as well as the code design pattern.
151+
152+
# License
153+
154+
The Laravel Application Logger is open-sourced software licensed under the [MIT license](LICENSE)

0 commit comments

Comments
 (0)