kodedphp /
logging
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the Koded package. |
||
| 5 | * |
||
| 6 | * (c) Mihail Binev <[email protected]> |
||
| 7 | * |
||
| 8 | * Please view the LICENSE distributed with this source code |
||
| 9 | * for the full copyright and license information. |
||
| 10 | * |
||
| 11 | */ |
||
| 12 | |||
| 13 | namespace Koded\Logging\Processors; |
||
| 14 | |||
| 15 | use Koded\Logging\Logger; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * System log. |
||
| 19 | * |
||
| 20 | * @link http://www.php.net/manual/en/function.openlog.php |
||
| 21 | */ |
||
| 22 | class Syslog extends Processor |
||
| 23 | { |
||
| 24 | protected string $format = '[levelname] message'; |
||
| 25 | |||
| 26 | 1 | protected function process(array $message): void |
|
| 27 | { |
||
| 28 | $levels = [ |
||
| 29 | 1 | Logger::DEBUG => LOG_DEBUG, |
|
| 30 | 1 | Logger::INFO => LOG_INFO, |
|
| 31 | 1 | Logger::NOTICE => LOG_NOTICE, |
|
| 32 | 1 | Logger::WARNING => LOG_WARNING, |
|
| 33 | 1 | Logger::ERROR => LOG_ERR, |
|
| 34 | 1 | Logger::CRITICAL => LOG_CRIT, |
|
| 35 | 1 | Logger::ALERT => LOG_ALERT, |
|
| 36 | 1 | Logger::EMERGENCY => LOG_EMERG |
|
| 37 | ]; |
||
| 38 | |||
| 39 | try { |
||
| 40 | 1 | \openlog(null, LOG_CONS, LOG_USER); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 41 | 1 | \syslog($levels[$message['level']] ?? LOG_DEBUG, \strtr($this->format, $message)); |
|
| 42 | 1 | } finally { |
|
| 43 | 1 | \closelog(); |
|
| 44 | } |
||
| 45 | 1 | } |
|
| 46 | } |
||
| 47 |