0 follower

Final Class Yiisoft\Log\Target\Syslog\SyslogTarget

InheritanceYiisoft\Log\Target\Syslog\SyslogTarget » Yiisoft\Log\Target

SyslogTarget writes log to syslog.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Log\Target\Syslog\SyslogTarget

Protected Methods

Hide inherited methods

Method Description Defined By
export() Writes log messages to syslog. Yiisoft\Log\Target\Syslog\SyslogTarget

Constants

Hide inherited constants

Constant Value Description Defined By
SYSLOG_LEVELS [ \Psr\Log\LogLevel::EMERGENCY => \LOG_EMERG, \Psr\Log\LogLevel::ALERT => \LOG_ALERT, \Psr\Log\LogLevel::CRITICAL => \LOG_CRIT, \Psr\Log\LogLevel::ERROR => \LOG_ERR, \Psr\Log\LogLevel::WARNING => \LOG_WARNING, \Psr\Log\LogLevel::NOTICE => \LOG_NOTICE, \Psr\Log\LogLevel::INFO => \LOG_INFO, \Psr\Log\LogLevel::DEBUG => \LOG_DEBUG, ] Yiisoft\Log\Target\Syslog\SyslogTarget

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $identity, integer $options LOG_ODELAY LOG_PID, integer $facility LOG_USER, string[] $levels = [] )
$identity string

The string that is prefixed to each message.

$options integer

Bit options to be used when generating a log message.

$facility integer

Used to specify what type of program is logging the message. This allows you to specify (in your machine's syslog configuration) how messages coming from different facilities will be handled.

$levels string[]

The {@see \Psr\Log\LogLevel log message levels} that this target is interested in.

                public function __construct(
    private string $identity,
    private int $options = LOG_ODELAY | LOG_PID,
    private int $facility = LOG_USER,
    array $levels = []
) {
    parent::__construct($levels);
    $this->setFormat(static function (Message $message) {
        return "[{$message->level()}][{$message->context('category', '')}] {$message->message()}";
    });
}

            
export() protected method
protected void export ( )
throws RuntimeException

If unable to export log through system log.

                protected function export(): void
{
    $formattedMessages = $this->getFormattedMessages();
    openlog($this->identity, $this->options, $this->facility);
    foreach ($this->getMessages() as $key => $message) {
        syslog(self::SYSLOG_LEVELS[$message->level()], $formattedMessages[$key]);
    }
    closelog();
}