Skip to content

Commit 403aa94

Browse files
committed
PHP warnings handling fixed
1 parent 3f2194f commit 403aa94

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ Methods for configure:
235235
disabled. If ```true``` - enabled, with PSR-3 logger messages will be sent to the ```ERROR``` level, without -
236236
to ```STDERR```. And you can pass custom log level (like ```$debugLog = Logger::WARNING```) to change the default
237237
PSR-3 channel.
238-
* ```$logUncaughtErrors``` (default ```false```) - registers shutdown function for log uncaught exceptions such as PHP
239-
fatal errors or incorrect task settings.
240-
* ```$logPhpWarningsToError``` (default ```false```) - If true, PHP non-fatal warnings will be sent to the error
241-
channel, otherwise to the debug channel.
238+
* ```$logUncaughtErrors``` (default ```false```) - registers shutdown function for log uncaught errors such as PHP
239+
errors or incorrect task settings.
240+
* ```$logWarningsToError``` (default ```false```) - ff true, PHP non-fatal errors will be sent to the error channel,
241+
otherwise - to the debug channel.
242242
* ```$logMessageFormat``` (default ```null```) - formatting template for task logger. Pass ```null``` for set default
243243
formatting (```"[{{task_id}}. {{TASK_TYPE}} '{{task_name}}']: {{message}}"```). Available variables:
244244
* ```{{task_id}}```

src/Config.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class Config
2424
*/
2525
private $errorLog;
2626
/**
27-
* Registers shutdown function for logging PHP runtime fatal errors that the scheduler cannot catch
27+
* Registers shutdown function for logging PHP errors
2828
* @var bool
2929
*/
3030
private $logUncaughtErrors;
3131
/**
32-
* If true, PHP warnings will be sent to the error channel, otherwise - to the debug channel
32+
* If true, PHP non-fatal errors will be sent to the error channel, otherwise - to the debug channel
3333
* @var bool
3434
*/
35-
private $logPhpWarningsToError;
35+
private $logWarningsToError;
3636
/**
3737
* Log message formatting string.
3838
* Available variables: {{task_id}}, {{task_type}}, {{TASK_TYPE}}, {{task_name}}, {{TASK_NAME}},
@@ -109,8 +109,8 @@ class Config
109109
* @param ?LoggerInterface $logger PSR-3 is a compatible logger. If null - the log will be sent to the STDOUT/STDERR.
110110
* @param mixed $debugLog False/null - debug log disabled. True - enabled (STDOUT/DEBUG). Or set custom PSR-3 level.
111111
* @param mixed $errorLog False/null - error log disabled. True - enabled (STDERR/ERROR). Or set custom PSR-3 level.
112-
* @param bool $logUncaughtErrors Registers shutdown function for logging PHP runtime fatal errors.
113-
* @param bool $logPhpWarningsToError If true, PHP warnings will be sent to the error channel, otherwise - to the debug channel.
112+
* @param bool $logUncaughtErrors Registers shutdown function for logging PHP errors.
113+
* @param bool $logWarningsToError If true, PHP non-fatal errors will be sent to the error channel, otherwise - to the debug channel
114114
* @param ?string $logMessageFormat Log message formatting string. Available {{task_id}}, {{task_type}}, {{task_name}},
115115
* {{message}} and {{task_description}} variables. Lowercase for regular case, uppercase - for forced uppercase.
116116
* Pass null for default formatting: "[{{task_id}}. {{TASK_TYPE}} '{{task_name}}']: {{message}}".
@@ -133,7 +133,7 @@ public function __construct(
133133
$debugLog = false,
134134
$errorLog = true,
135135
bool $logUncaughtErrors = false,
136-
bool $logPhpWarningsToError = false,
136+
bool $logWarningsToError = false,
137137
?string $logMessageFormat = null,
138138
?int $maxLogMsgLength = null,
139139
?array $exceptionLogMatching = [],
@@ -151,7 +151,7 @@ public function __construct(
151151
$this->debugLog = $debugLog;
152152
$this->errorLog = $errorLog;
153153
$this->logUncaughtErrors = $logUncaughtErrors;
154-
$this->logPhpWarningsToError = $logPhpWarningsToError;
154+
$this->logWarningsToError = $logWarningsToError;
155155
$this->logMessageFormat = $logMessageFormat ?? "[{{task_id}}. {{TASK_TYPE}} '{{task_name}}']: {{message}}";
156156

157157
if ($maxLogMsgLength !== null && $maxLogMsgLength <= 0) {
@@ -224,7 +224,7 @@ public function getErrorLog()
224224
}
225225

226226
/**
227-
* Registers shutdown function for logging PHP runtime fatal errors that the scheduler cannot catch
227+
* Registers shutdown function for logging PHP errors
228228
* @return bool
229229
*/
230230
public function getLogUncaughtErrors(): bool
@@ -233,12 +233,12 @@ public function getLogUncaughtErrors(): bool
233233
}
234234

235235
/**
236-
* If true, PHP warnings will be sent to the error channel, otherwise - to the debug channel
236+
* If true, PHP non-fatal errors will be sent to the error channel, otherwise - to the debug channel
237237
* @return bool
238238
*/
239-
public function getLogPhpWarningsToError(): bool
239+
public function getLogWarningsToError(): bool
240240
{
241-
return $this->logPhpWarningsToError;
241+
return $this->logWarningsToError;
242242
}
243243

244244
/**

src/Wrapper/TaskWrapper.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public function logDebug(string $message): void
501501

502502
/**
503503
* Log message to error channel
504-
* @param string $header
504+
* @param string $message
505505
* @param Throwable|null $e
506506
*/
507507
public function logError(string $message, ?Throwable $e = null): void
@@ -544,9 +544,9 @@ private function phpErrorHandler($code, $message, $file, $line): void
544544
if (array_key_exists($code, PhpErrors::FATAL)) {
545545
$errName = PhpErrors::FATAL[$code];
546546
throw new Exception("(ATTENTION: PHP $errName) - $message", $code);
547-
} else {
547+
} elseif ($this->config->getLogUncaughtErrors()) {
548548
$message = (PhpErrors::SOFT[$code] ?? 0) . " - $message (code $code, file $file, line $line)";
549-
$this->config->getLogPhpWarningsToError() ?
549+
$this->config->getLogWarningsToError() ?
550550
$this->logError($message) :
551551
$this->logDebug($message);
552552

0 commit comments

Comments
 (0)