1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-18 23:26:20 +02:00

Convert level/levelName to enums (#1656)

This commit is contained in:
Jordi Boggiano
2022-04-19 21:49:03 +02:00
committed by GitHub
parent 248673e858
commit 2d006a8472
138 changed files with 1297 additions and 1216 deletions

View File

@@ -11,14 +11,12 @@
namespace Monolog\Handler;
use Monolog\Logger;
use Monolog\Level;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
/**
* Common syslog functionality
*
* @phpstan-import-type Level from \Monolog\Logger
*/
abstract class AbstractSyslogHandler extends AbstractProcessingHandler
{
@@ -27,54 +25,55 @@ abstract class AbstractSyslogHandler extends AbstractProcessingHandler
/**
* Translates Monolog log levels to syslog log priorities.
* @var array
* @phpstan-var array<Level, int>
*/
protected $logLevels = [
Logger::DEBUG => LOG_DEBUG,
Logger::INFO => LOG_INFO,
Logger::NOTICE => LOG_NOTICE,
Logger::WARNING => LOG_WARNING,
Logger::ERROR => LOG_ERR,
Logger::CRITICAL => LOG_CRIT,
Logger::ALERT => LOG_ALERT,
Logger::EMERGENCY => LOG_EMERG,
];
protected function toSyslogPriority(Level $level): int
{
return match ($level) {
Level::Debug => \LOG_DEBUG,
Level::Info => \LOG_INFO,
Level::Notice => \LOG_NOTICE,
Level::Warning => \LOG_WARNING,
Level::Error => \LOG_ERR,
Level::Critical => \LOG_CRIT,
Level::Alert => \LOG_ALERT,
Level::Emergency => \LOG_EMERG,
};
}
/**
* List of valid log facility names.
* @var array<string, int>
*/
protected $facilities = [
'auth' => LOG_AUTH,
'authpriv' => LOG_AUTHPRIV,
'cron' => LOG_CRON,
'daemon' => LOG_DAEMON,
'kern' => LOG_KERN,
'lpr' => LOG_LPR,
'mail' => LOG_MAIL,
'news' => LOG_NEWS,
'syslog' => LOG_SYSLOG,
'user' => LOG_USER,
'uucp' => LOG_UUCP,
'auth' => \LOG_AUTH,
'authpriv' => \LOG_AUTHPRIV,
'cron' => \LOG_CRON,
'daemon' => \LOG_DAEMON,
'kern' => \LOG_KERN,
'lpr' => \LOG_LPR,
'mail' => \LOG_MAIL,
'news' => \LOG_NEWS,
'syslog' => \LOG_SYSLOG,
'user' => \LOG_USER,
'uucp' => \LOG_UUCP,
];
/**
* @param string|int $facility Either one of the names of the keys in $this->facilities, or a LOG_* facility constant
*/
public function __construct($facility = LOG_USER, $level = Logger::DEBUG, bool $bubble = true)
public function __construct($facility = \LOG_USER, $level = Level::Debug, bool $bubble = true)
{
parent::__construct($level, $bubble);
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->facilities['local0'] = LOG_LOCAL0;
$this->facilities['local1'] = LOG_LOCAL1;
$this->facilities['local2'] = LOG_LOCAL2;
$this->facilities['local3'] = LOG_LOCAL3;
$this->facilities['local4'] = LOG_LOCAL4;
$this->facilities['local5'] = LOG_LOCAL5;
$this->facilities['local6'] = LOG_LOCAL6;
$this->facilities['local7'] = LOG_LOCAL7;
$this->facilities['local0'] = \LOG_LOCAL0;
$this->facilities['local1'] = \LOG_LOCAL1;
$this->facilities['local2'] = \LOG_LOCAL2;
$this->facilities['local3'] = \LOG_LOCAL3;
$this->facilities['local4'] = \LOG_LOCAL4;
$this->facilities['local5'] = \LOG_LOCAL5;
$this->facilities['local6'] = \LOG_LOCAL6;
$this->facilities['local7'] = \LOG_LOCAL7;
} else {
$this->facilities['local0'] = 128; // LOG_LOCAL0
$this->facilities['local1'] = 136; // LOG_LOCAL1