Skip to content

Commit 96c684e

Browse files
committed
restructure README optional features
made Writer constructor props readonly
1 parent 6e9b7a8 commit 96c684e

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,20 @@ It reports a lot of metadata like total query count, total execution time, origi
6767

6868
5. Make sure on live server you will set logging SQL queries to false in your `.env` file: `SQL_REPORTER_QUERIES_ENABLED=false`. This package is recommended to be used only for development to not impact production application performance.
6969

70-
## `QueryLogWritten` event
70+
## Optional
71+
72+
### GeoIP support
73+
74+
For optional GeoIP support (adding country information to client IP in log headers), you may install [stevebauman/location](https://github.com/stevebauman/location) in your project:
75+
76+
```bash
77+
$ composer require stevebauman/location
78+
$ php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"
79+
```
80+
81+
It will be auto-detected, no configuration needed for this. If you wish to use a different driver than the default [IpApi](https://ip-api.com/), e.g. `MaxMind` make sure you correctly configure it according to the docs: [Available Drivers](https://github.com/stevebauman/location#available-drivers)
82+
83+
### `QueryLogWritten` event
7184

7285
This package fires a `QueryLogWritten` event after the log file has been written. You may use this event to further debug or analyze the logged queries in your application. The queries are filtered by the `SQL_REPORTER_QUERIES_REPORT_PATTERN` setting, which comes with a sensible default to exclude `SELECT` queries and some default tables like `sessions`, `jobs`, `bans`, `logins`. If you don't want to filter any queries, you may leave this setting empty.
7386
@@ -83,16 +96,7 @@ Writer::shouldReportQuery(function (SqlQuery $query) {
8396
});
8497
```
8598
86-
## Optional
87-
88-
For optional GeoIP support (adding country information to client IP in log headers), you may install [stevebauman/location](https://github.com/stevebauman/location) in your project:
89-
90-
```bash
91-
$ composer require stevebauman/location
92-
$ php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"
93-
```
94-
95-
It will be auto-detected, no configuration needed for this. If you wish to use a different driver than the default [IpApi](https://ip-api.com/), e.g. `MaxMind` make sure you correctly configure it according to the docs: [Available Drivers](https://github.com/stevebauman/location#available-drivers)
99+
With the `SqlQuery` object, you have access to both `$rawQuery` and the (unprepared) `$query`/`$bindings`. The filter possibilities by providing a callback to `Writer::shouldReportQuery()` are endless!
96100
97101
## Development
98102
@@ -103,10 +107,10 @@ $ git clone https://github.com/onlime/laravel-sql-reporter.git
103107
$ cd laravel-sql-reporter
104108
$ composer install
105109
106-
# run unit tests
107-
$ vendor/bin/phpunit
110+
# run both Feature and Unit tests
111+
$ vendor/bin/pest
108112
# run unit tests with coverage report
109-
$ XDEBUG_MODE=coverage vendor/bin/phpunit
113+
$ vendor/bin/pest --coverage
110114
```
111115
112116
## FAQ
@@ -168,8 +172,8 @@ All changes are listed in [CHANGELOG](CHANGELOG.md)
168172
169173
## Caveats
170174
171-
- If your application crashes, this package will not log any queries, as logging is only triggered at the end. As alternative, you could use [mnabialek/laravel-sql-logger](https://github.com/mnabialek/laravel-sql-logger) which triggers sql logging on each query execution.
172-
- It's currently not possible to log slow queries into a separate logfile. I wanted to keep that package simpel.
175+
- If your application crashes, this package will not log any queries, as logging is only triggered at the end of the request cycle. As alternative, you could use [mnabialek/laravel-sql-logger](https://github.com/mnabialek/laravel-sql-logger) which triggers sql logging on each query execution.
176+
- It's currently not possible to log slow queries into a separate logfile. I wanted to keep that package simple.
173177
174178
## TODO
175179

src/Providers/SqlReporterServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SqlReporterServiceProvider extends ServiceProvider
1717
/**
1818
* {@inheritdoc}
1919
*/
20-
public function register()
20+
public function register(): void
2121
{
2222
$this->config = $this->app->make(Config::class);
2323

@@ -31,7 +31,7 @@ public function register()
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function boot()
34+
public function boot(): void
3535
{
3636
$this->publishes([
3737
$this->configFileLocation() => config_path('sql-reporter.php'),

src/Writer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Writer
2929
private static ?Closure $shouldReportQuery = null;
3030

3131
public function __construct(
32-
private Formatter $formatter,
33-
private Config $config,
34-
private FileName $fileName
32+
private readonly Formatter $formatter,
33+
private readonly Config $config,
34+
private readonly FileName $fileName
3535
) {
3636
}
3737

0 commit comments

Comments
 (0)