diff --git a/src/Profiler.php b/src/Profiler.php index 96bac27..c423bcd 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -9,6 +9,7 @@ class Profiler const LOG_OFF = 0; const LOG_ERRORS_ONLY = 1; const LOG_ALWAYS = 2; + const LOG_ABOVE_THRESHOLD = 3; /** * @var array @@ -80,11 +81,15 @@ public function getProfilerOutput($httpCode, $dbProfiler = 0, $responseElapsedTi : []; } - public function getTaskerProfilerOutput($executionTime = 0, $dbProfiler = 2) + public function getTaskerProfilerOutput($taskStatus, $executionTime = 0) { - return $this->hasProfilers() && $this->shouldLogProfiler(200, $executionTime) - ? $this->getFormatted($dbProfiler, $executionTime) - : []; + if (!$this->hasProfilers()) { + return null; + } + if (!$this->shouldLogTaskerProfiler($taskStatus, $executionTime)) { + return null; + } + return $this->getFormatted(2, $executionTime); } public function getProfilerSummary() @@ -105,7 +110,6 @@ private function shouldLogProfiler($httpCode, $responseElapsedTime) if ($this->logLevel === self::LOG_ALWAYS) { return true; } - if ($this->isRequestTresholdExceded($responseElapsedTime)) { return true; } @@ -113,6 +117,23 @@ private function shouldLogProfiler($httpCode, $responseElapsedTime) return self::LOG_ERRORS_ONLY && substr($httpCode, 0, 1) != 2; } + private function shouldLogTaskerProfiler($taskStatus, $execTime) + { + if ($this->logLevel === self::LOG_OFF) { + return false; + } + if ($this->logLevel === self::LOG_ALWAYS) { + return true; + } + if ($this->logLevel === self::LOG_ABOVE_THRESHOLD + && $this->isRequestTresholdExceded($execTime) + ) { + return true; + } + + return self::LOG_ERRORS_ONLY && (int) $taskStatus != 2; + } + public function isRequestTresholdExceded($responseElapsedTime) { return $this->threshold && $responseElapsedTime > $this->threshold;