@@ -9,6 +9,7 @@ class Profiler
99 const LOG_OFF = 0 ;
1010 const LOG_ERRORS_ONLY = 1 ;
1111 const LOG_ALWAYS = 2 ;
12+ const LOG_ABOVE_THRESHOLD = 3 ;
1213
1314 /**
1415 * @var array
@@ -80,11 +81,15 @@ public function getProfilerOutput($httpCode, $dbProfiler = 0, $responseElapsedTi
8081 : [];
8182 }
8283
83- public function getTaskerProfilerOutput ($ executionTime = 0 , $ dbProfiler = 2 )
84+ public function getTaskerProfilerOutput ($ taskStatus , $ executionTime = 0 )
8485 {
85- return $ this ->hasProfilers () && $ this ->shouldLogProfiler (200 , $ executionTime )
86- ? $ this ->getFormatted ($ dbProfiler , $ executionTime )
87- : [];
86+ if (!$ this ->hasProfilers ()) {
87+ return null ;
88+ }
89+ if (!$ this ->shouldLogTaskerProfiler ($ taskStatus , $ executionTime )) {
90+ return null ;
91+ }
92+ return $ this ->getFormatted (2 , $ executionTime );
8893 }
8994
9095 public function getProfilerSummary ()
@@ -105,14 +110,30 @@ private function shouldLogProfiler($httpCode, $responseElapsedTime)
105110 if ($ this ->logLevel === self ::LOG_ALWAYS ) {
106111 return true ;
107112 }
108-
109113 if ($ this ->isRequestTresholdExceded ($ responseElapsedTime )) {
110114 return true ;
111115 }
112116
113117 return self ::LOG_ERRORS_ONLY && substr ($ httpCode , 0 , 1 ) != 2 ;
114118 }
115119
120+ private function shouldLogTaskerProfiler ($ taskStatus , $ execTime )
121+ {
122+ if ($ this ->logLevel === self ::LOG_OFF ) {
123+ return false ;
124+ }
125+ if ($ this ->logLevel === self ::LOG_ALWAYS ) {
126+ return true ;
127+ }
128+ if ($ this ->logLevel === self ::LOG_ABOVE_THRESHOLD
129+ && $ this ->isRequestTresholdExceded ($ execTime )
130+ ) {
131+ return true ;
132+ }
133+
134+ return self ::LOG_ERRORS_ONLY && (int ) $ taskStatus != 2 ;
135+ }
136+
116137 public function isRequestTresholdExceded ($ responseElapsedTime )
117138 {
118139 return $ this ->threshold && $ responseElapsedTime > $ this ->threshold ;
0 commit comments