Skip to content

Commit f493a56

Browse files
authored
Merge pull request #12 from UrosPurtic/release/0.x
Based on response elapsed time add a profiler data to response log
2 parents c4e9055 + fe974e5 commit f493a56

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/Profiler.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class Profiler
3030
*/
3131
private $logLevel;
3232

33+
/**
34+
* @var int
35+
*/
36+
private $threshold;
37+
3338
public function __construct()
3439
{
3540
$this->profilers = [];
@@ -59,12 +64,18 @@ public function setLogLevel($logLevel)
5964
return $this;
6065
}
6166

67+
public function setThreshold($threshold)
68+
{
69+
$this->threshold = (int) $threshold;
70+
return $this;
71+
}
72+
6273
/**
6374
* @return array
6475
*/
65-
public function getProfilerOutput($httpCode, $dbProfiler = 0)
76+
public function getProfilerOutput($httpCode, $dbProfiler = 0, $responseElapsedTime = 0)
6677
{
67-
return $this->hasProfilers() && $this->shouldLogProfiler($httpCode)
78+
return $this->hasProfilers() && $this->shouldLogProfiler($httpCode, $responseElapsedTime)
6879
? $this->getFormatted($dbProfiler)
6980
: [];
7081
}
@@ -74,14 +85,19 @@ public function getProfilerSummary()
7485
return (new ProfilerSummary($this->profilers))->getSummary();
7586
}
7687

77-
private function shouldLogProfiler($httpCode)
88+
private function shouldLogProfiler($httpCode, $responseElapsedTime)
7889
{
7990
if ($this->logLevel === self::LOG_OFF) {
8091
return false;
8192
}
8293
if ($this->logLevel === self::LOG_ALWAYS) {
8394
return true;
8495
}
96+
97+
if($this->threshold && $responseElapsedTime > $this->threshold){
98+
return true;
99+
}
100+
85101
return self::LOG_ERRORS_ONLY && substr($httpCode, 0, 1) != 2;
86102
}
87103

src/RunnerAbstract.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ public function setProfilerLogLevel($profilerLogLevel)
123123
return $this;
124124
}
125125

126+
public function setProfilerLogThreshold($threshold)
127+
{
128+
$this->profiler->setThreshold($threshold);
129+
return $this;
130+
}
131+
126132
/**
127133
* @return Profiler
128134
*/

0 commit comments

Comments
 (0)