You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in console to install this module (Notice `--dev` flag - it's recommended to use this package only for development).
22
+
in console to install this module (Notice `--dev` flag - it's recommended to use this package only for development).
23
23
24
24
Laravel uses package auto-discovery, and it will automatically load this service provider, so you don't need to add anything into the `providers` section of `config/app.php`.
25
-
25
+
26
26
2. Run the following in your console to publish the default configuration file:
If you have also `.env.example` it's recommended to add those entries also in `.env.example` file just to make sure everyone knows about those env variables. Be aware that `SQL_REPORTER_DIRECTORY` is directory inside storage directory.
63
-
63
+
64
64
To find out more about those setting please take a look at [Configuration file](config/sql-reporter.php)
65
-
65
+
66
66
4. Make sure directory specified in `.env` file exists in storage path, and you have valid permissions to create and modify files in this directory (If it does not exist this package will automatically create it when needed, but it's recommended to create it manually with valid file permissions)
67
67
68
68
5. Make sure on live server you will set logging SQL queries to falsein your `.env` file: `SQL_REPORTER_QUERIES_ENABLED=false`. This package is recommended to be used only for development to not impact production application performance.
69
69
70
70
## Optional
71
71
72
+
### GeoIP support
73
+
72
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:
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)
80
82
83
+
### `QueryLogWritten` event
84
+
85
+
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.
86
+
87
+
In addition to the pattern, you may also configure a callback to define your own custom filtering logic, for example, in your `AppServiceProvider`:
// Only include queries in the `QueryLogWritten` event that took longer than 100ms
95
+
return $query->time > 100;
96
+
});
97
+
```
98
+
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!
@@ -101,7 +121,7 @@ This package was inspired by [mnabialek/laravel-sql-logger](https://github.com/m
101
121
102
122
- Query logging is not triggered upon each query execution but instead at a final step, using `RequestHandled` and `CommandFinished` events.
103
123
- This allows us to include much more information about the whole query executions like total query count, total execution time, and very detailed header information like origin (request URL/console command), authenticated user, app environment, client browser agent / IP / hostname.
104
-
- This package is greatly simplified and only provides support for Laravel 10+ / PHP 8.1+
124
+
- This package is greatly simplified and only provides support for Laravel 10+ / PHP 8.2+
105
125
- It uses the Laravel built-in query logging (`DB::enableQueryLog()`) which logs all queries in memory, which should perform much better than writing every single query to the log file.
106
126
- By default, `onlime/laravel-sql-reporter` produces much nicer log output, especially since we only write header information before the first query.
107
127
@@ -152,8 +172,8 @@ All changes are listed in [CHANGELOG](CHANGELOG.md)
152
172
153
173
## Caveats
154
174
155
-
- 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.
156
-
- 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.
0 commit comments