Skip to content

Commit c4a6df0

Browse files
authored
Merge pull request #1 from onlime/develop
Use new getRawQueryLog() from Laravel v10.15
2 parents 9dda51a + d3559d1 commit c4a6df0

19 files changed

+167
-502
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# CHANGELOG
22

3-
## [1.0.x (Unreleased)](https://github.com/onlime/laravel-sql-reporter/compare/v1.0.1...main)
3+
## [1.1.x (Unreleased)](https://github.com/onlime/laravel-sql-reporter/compare/v1.1.0...main)
44

55
- ...
66

7+
## [1.1.0 (2023-07-16)](https://github.com/onlime/laravel-sql-reporter/compare/v1.0.1...v1.1.0)
8+
9+
- Drop Laravel 9 support, require Laravel v10.15 or higher for the new [`DB::getRawQueryLog()`](https://github.com/laravel/framework/pull/47507) support.
10+
- PHP code style fixes by `laravel/pint` v1.10, now using more strict style rules (`laravel` preset).
11+
- Refactored whole codebase from `DB::getQueryLog()` to use the new `DB::getRawQueryLog()` method, so `ReplacesBindings` is no longer needed.
12+
- Replaced [torann/geoip](https://github.com/Torann/laravel-geoip) by [stevebauman/location](https://github.com/stevebauman/location) for optional GeoIP support.
13+
- Improved username detection in `Formatter` headers, so that it works both with default `email` field or custom `username()` method on `User` model.
14+
715
## [1.0.1 (2023-02-26)](https://github.com/onlime/laravel-sql-reporter/compare/v1.0.0...v1.0.1)
816

917
- Allow bindings to be null.

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
This module allows you to log SQL queries to log file in Laravel framework. It's useful mainly
1010
when developing your application to verify whether your queries are valid and to make sure your application doesn't run too many or too slow database queries.
1111

12-
You may also use this in production as it should not cause a lot of overhead. Logged queries can be limited by query pattern, and logging only occurs at the end of each request or artisan command execution.
12+
You may also use this in production as it should not cause a lot of overhead. Logged queries can be limited by query pattern, and logging only occurs at the end of each request or artisan command execution, not per query execution.
1313

1414
It reports a lot of metadata like total query count, total execution time, origin (request URL/console command), authenticated user, app environment, client browser agent / IP / hostname.
1515

@@ -22,9 +22,9 @@ It reports a lot of metadata like total query count, total execution time, origi
2222
in console to install this module (Notice `--dev` flag - it's recommended to use this package only for development).
2323

2424
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+
2626
2. Run the following in your console to publish the default configuration file:
27-
27+
2828
```bash
2929
$ php artisan vendor:publish --provider="Onlime\LaravelSqlReporter\Providers\ServiceProvider"
3030
```
@@ -57,25 +57,25 @@ It reports a lot of metadata like total query count, total execution time, origi
5757
SQL_REPORTER_QUERIES_INCLUDE_PATTERN="/^(?!SELECT).*/i"
5858
SQL_REPORTER_QUERIES_EXCLUDE_PATTERN="/^UPDATE.*(last_visit|remember_token)/i"
5959
```
60-
60+
6161
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.
62-
62+
6363
To find out more about those setting please take a look at [Configuration file](config/sql-reporter.php)
64-
64+
6565
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)
6666

6767
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.
6868

6969
## Optional
7070

71-
For optional GeoIP support (adding country information to client IP in log headers), you may install [torann/geoip](https://github.com/Torann/laravel-geoip) in your project:
71+
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:
7272

7373
```bash
74-
$ composer require torann/geoip
75-
$ php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider"
74+
$ composer require stevebauman/location
75+
$ php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"
7676
```
7777

78-
It will be auto-detected, no configuration needed for this.
78+
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)
7979

8080
## Development
8181

@@ -100,7 +100,7 @@ This package was inspired by [mnabialek/laravel-sql-logger](https://github.com/m
100100
101101
- Query logging is not triggered upon each query execution but instead at a final step, using `RequestHandled` and `CommandFinished` events.
102102
- 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.
103-
- This package is greatly simplified and only provides support for Laravel 8+ / PHP 8
103+
- This package is greatly simplified and only provides support for Laravel 10 / PHP 8.1+
104104
- 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.
105105
- By default, `onlime/laravel-sql-reporter` produces much nicer log output, especially since we only write header information before the first query.
106106
@@ -153,12 +153,11 @@ All changes are listed in [CHANGELOG](CHANGELOG.md)
153153
- 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.
154154
- It's currently not possible to log slow queries into a separate logfile. I wanted to keep that package simpel.
155155

156-
## Todo
156+
## TODO
157157

158158
- [ ] Improve unit testing to reach 100% coverage
159159
- [ ] Integrate Coveralls.io and add test coverage status badge to README
160-
- [ ] Add browser type information to log headers, using hisorange/browser-detect
161-
- [ ] Support for Lumen
160+
- [ ] Add browser type information to log headers, maybe using [hisorange/browser-detect](https://github.com/hisorange/browser-detect)
162161

163162
## License
164163

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
],
1616
"require": {
1717
"php": "^8.1",
18-
"illuminate/support": "^9.0 || ^10.0",
19-
"illuminate/filesystem": "^9.0 || ^10.0",
20-
"illuminate/container": "^9.0 || ^10.0",
18+
"illuminate/support": "^10.15.0",
19+
"illuminate/filesystem": "^10.15.0",
20+
"illuminate/container": "^10.15.0",
2121
"nesbot/carbon": "^2.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^9.5",
24+
"phpunit/phpunit": "^10.2",
2525
"mockery/mockery": "^1.0",
26-
"laravel/framework": "^9.0 || ^10.0",
27-
"laravel/pint": "^1.5"
26+
"laravel/framework": "^10.15.0",
27+
"laravel/pint": "^1.10"
2828
},
2929
"autoload": {
3030
"psr-4": {
@@ -47,7 +47,7 @@
4747
"url": "https://github.com/mnabialek/laravel-version"
4848
},
4949
"suggest": {
50-
"torann/geoip": "GeoIP country detection for log headers information",
50+
"stevebaumann/location": "GeoIP country detection for log headers information",
5151
"symfony/thanks": "Star packages you use running 'composer thanks' command"
5252
}
5353
}

phpunit.xml

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
>
7-
<coverage>
8-
<include>
9-
<directory suffix=".php">./src</directory>
10-
</include>
11-
<report>
12-
<html outputDirectory="./tests/_coverage" lowUpperBound="35" highLowerBound="70"/>
13-
<text outputFile="php://stdout" showUncoveredFiles="true"/>
14-
</report>
15-
</coverage>
16-
<testsuites>
17-
<testsuite name="Unit">
18-
<directory suffix="Test.php">./tests/Unit</directory>
19-
</testsuite>
20-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
3+
<coverage>
4+
<report>
5+
<html outputDirectory="./tests/_coverage" lowUpperBound="35" highLowerBound="70"/>
6+
<text outputFile="php://stdout" showUncoveredFiles="true"/>
7+
</report>
8+
</coverage>
9+
<testsuites>
10+
<testsuite name="Unit">
11+
<directory>./tests/Unit</directory>
12+
</testsuite>
13+
</testsuites>
14+
<source>
15+
<include>
16+
<directory>./src</directory>
17+
</include>
18+
</source>
2119
</phpunit>

pint.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
{
22
"preset": "laravel",
33
"rules": {
4-
"braces": false,
54
"blank_line_before_statement": false,
6-
"class_definition": false,
75
"binary_operator_spaces": false,
8-
"concat_space": false,
9-
"no_unused_imports": false,
106
"phpdoc_separation": false,
11-
"Laravel/laravel_phpdoc_alignment": false,
127
"modernize_strpos": true
138
},
149
"exclude": [

src/Concerns/ReplacesBindings.php

Lines changed: 0 additions & 125 deletions
This file was deleted.

src/Config.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
class Config
88
{
9-
/**
10-
* Config constructor.
11-
*/
129
public function __construct(
1310
protected ConfigRepository $repository
1411
) {

src/FileName.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
class FileName
99
{
10-
/**
11-
* FileName constructor.
12-
*/
1310
public function __construct(
1411
private Container $app,
1512
private Config $config
@@ -22,8 +19,8 @@ public function __construct(
2219
public function getLogfile(): string
2320
{
2421
return
25-
$this->parseFileName($this->config->queriesFileName()) .
26-
$this->suffix() .
22+
$this->parseFileName($this->config->queriesFileName()).
23+
$this->suffix().
2724
$this->config->fileExtension();
2825
}
2926

0 commit comments

Comments
 (0)