1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mnabialek\LaravelSqlLogger; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository; |
6
|
|
|
|
7
|
|
|
class Config |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var ConfigRepository |
11
|
|
|
*/ |
12
|
|
|
protected $repository; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Config constructor. |
16
|
|
|
* |
17
|
|
|
* @param ConfigRepository $repository |
18
|
|
|
*/ |
19
|
|
|
public function __construct(ConfigRepository $repository) |
20
|
|
|
{ |
21
|
|
|
$this->repository = $repository; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get directory where log files should be saved. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function logDirectory() |
30
|
|
|
{ |
31
|
|
|
return $this->repository->get('sql_logger.general.directory'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Whether query execution time should be converted to seconds. |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function useSeconds() |
40
|
|
|
{ |
41
|
|
|
return (bool) $this->repository->get('sql_logger.general.use_seconds'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get suffix for console logs. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function consoleSuffix() |
50
|
|
|
{ |
51
|
|
|
return (string) $this->repository->get('sql_logger.general.console_log_suffix'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get file extension for logs. |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function fileExtension() |
60
|
|
|
{ |
61
|
|
|
return $this->repository->get('sql_logger.general.extension'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Whether all queries should be logged. |
66
|
|
|
* |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function logAllQueries() |
70
|
|
|
{ |
71
|
|
|
return (bool) $this->repository->get('sql_logger.all_queries.enabled'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Whether SQL log should be overridden for each request. |
76
|
|
|
* |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public function overrideFile() |
80
|
|
|
{ |
81
|
|
|
return (bool) $this->repository->get('sql_logger.all_queries.override_log'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get pattern for all queries. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function allQueriesPattern() |
90
|
|
|
{ |
91
|
|
|
return $this->repository->get('sql_logger.all_queries.pattern'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get file name (without extension) for all queries. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function allQueriesFileName() |
100
|
|
|
{ |
101
|
|
|
return $this->repository->get('sql_logger.all_queries.file_name'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Whether slow queries should be logged. |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function logSlowQueries() |
110
|
|
|
{ |
111
|
|
|
return (bool) $this->repository->get('sql_logger.slow_queries.enabled'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Minimum execution time (in milliseconds) to consider query as slow. |
116
|
|
|
* |
117
|
|
|
* @return float |
118
|
|
|
*/ |
119
|
|
|
public function slowLogTime() |
120
|
|
|
{ |
121
|
|
|
return $this->repository->get('sql_logger.slow_queries.min_exec_time'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get pattern for slow queries. |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function slowQueriesPattern() |
130
|
|
|
{ |
131
|
|
|
return $this->repository->get('sql_logger.slow_queries.pattern'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get file name (without extension) for slow queries. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
public function slowQueriesFileName() |
140
|
|
|
{ |
141
|
|
|
return $this->repository->get('sql_logger.slow_queries.file_name'); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|