-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql-reporter.php
130 lines (115 loc) · 5 KB
/
sql-reporter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
return [
'general' => [
/*
* Directory where log files will be saved
*/
'directory' => storage_path(env('SQL_REPORTER_DIRECTORY', 'logs/sql')),
/*
* Whether execution time in log file should be displayed in seconds
* (by default it's in milliseconds)
*/
'use_seconds' => env('SQL_REPORTER_USE_SECONDS', false),
/*
* Suffix for Artisan queries logs (if it's empty same logfile will be used for Artisan)
*/
'console_log_suffix' => env('SQL_REPORTER_CONSOLE_SUFFIX', ''),
/*
* Extension for log files
*/
'extension' => env('SQL_REPORTER_LOG_EXTENSION', '.sql'),
],
'formatting' => [
/*
* Header fields, comma-separated. Available options:
*
* - datetime: date and time when the first query was executed
* - origin: where this query coming from - method/request or artisan command
* - status: total query count and execution time for all queries
* - user: username of authenticated user
* - guard: name of the auth guard (defaults to 'web' if not logged in)
* - env: application environment
* - agent: user agent
* - ip: (request-only) remote user IP
* - host: (request-only) remote user hostname (resolved IP)
* - referer: (request-only) browser referer
*
* It does not harm to keep all fields enabled. The request-only fields would simply report some standard/empty
* data if origin is an Artisan command.
*/
'header_fields' => array_filter(explode(',', env('SQL_REPORTER_FORMAT_HEADER_FIELDS',
'datetime,origin,status,user,guard,env,agent,ip,host,referer'
))),
/*
* Header datetime format.
*/
'header_datetime_format' => env('SQL_REPORTER_FORMAT_HEADER_DATETIME_FORMAT', 'Y-m-d H:i:s P'),
/*
* Single entry format. Available options:
*
* - [query_nr] - query number
* - [datetime] - date and time when query was executed
* - [query_time] - how long query was executed
* - [query] - query itself
* - [separator] - extra separator line to make it easier to see where next query starts
* - \n - new line separator.
*/
'entry_format' => env('SQL_REPORTER_FORMAT_ENTRY_FORMAT',
"-- Query [query_nr] [[query_time]]\n[query]"
),
],
'queries' => [
/*
* Whether all SQL queries should be logged
*/
'enabled' => env('SQL_REPORTER_QUERIES_ENABLED', true),
/*
* Whether log (for all queries, not for slow queries) should be overridden.
* It might be useful when you test some functionality, and you want to
* compare your queries (or number of queries) - be aware that when using
* AJAX it will override your log file in each request
*/
'override_log' => env('SQL_REPORTER_QUERIES_OVERRIDE_LOG', false),
/*
* Pattern that should be matched to log query. By default, all queries are logged.
*
* examples:
* '#.*#i' will log all queries
* '/^SELECT.*$/i' will log only SELECT queries
* '/^(?!SELECT).*$/i' will log all queries other than SELECT (modifying queries)
*/
'include_pattern' => env('SQL_REPORTER_QUERIES_INCLUDE_PATTERN', '/.*/i'),
/*
* Pattern that should not be matched to log query. This limits the queries that were
* matched by 'include_pattern'. By default, no queries are excluded.
*
* examples:
* '/^$/' don't exclude any queries
* '/^UPDATE.*last_visit/i' excludes UPDATE queries that modify `last_visit`
*/
'exclude_pattern' => env('SQL_REPORTER_QUERIES_EXCLUDE_PATTERN', '/^$/'),
/*
* Pattern which is used to detect DML queries.
* (Data Manipulation Language - INSERT, UPDATE, DELETE, etc.)
* see https://regex101.com/r/vB1QAM/1
*/
'report_pattern' => env(
'SQL_REPORTER_QUERIES_REPORT_PATTERN',
'/^(?!select\s|start transaction|commit|(insert into|update|delete from) `(sessions|jobs|bans|logins)`).*/i'
),
/*
* Only log queries with slow execution time (in milliseconds)
*/
'min_exec_time' => env('SQL_REPORTER_QUERIES_MIN_EXEC_TIME', 0),
/*
* Log file name without extension - elements between [ and ] characters will be parsed
* according to format used by https://www.php.net/manual/en/function.date.php
*
* examples:
* '[Y-m]-log' (default) results in YYYY-MM-log.sql logfile (monthly rotations)
* '[Y-m-d]-log' results in YYYY-MM-DD-log.sql logfile (daily rotations)
* 'query-log' results in query-log.sql (you should use logrotate for rotation)
*/
'file_name' => env('SQL_REPORTER_QUERIES_FILE_NAME', '[Y-m]-log'),
],
];