mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-22 17:16:18 +02:00
Fix for SyslogUdpHandler timezone issue
Hello! As described in [this issue](https://github.com/Seldaek/monolog/issues/1350), SyslogUdpHandler doesn't respect `Logger` timezone setting for IETF (RFC-5424) syslog format. This PR is a fix for this issue.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\DateTimeImmutable;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\SyslogUdp\UdpSocket;
|
||||
|
||||
@@ -57,7 +58,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler
|
||||
{
|
||||
$lines = $this->splitMessageIntoLines($record['formatted']);
|
||||
|
||||
$header = $this->makeCommonSyslogHeader($this->logLevels[$record['level']]);
|
||||
$header = $this->makeCommonSyslogHeader($this->logLevels[$record['level']], $record['datetime']);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$this->socket->write($line, $header);
|
||||
@@ -81,7 +82,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler
|
||||
/**
|
||||
* Make common syslog header (see rfc5424 or rfc3164)
|
||||
*/
|
||||
protected function makeCommonSyslogHeader(int $severity): string
|
||||
protected function makeCommonSyslogHeader(int $severity, DateTimeImmutable $datetime): string
|
||||
{
|
||||
$priority = $severity + $this->facility;
|
||||
|
||||
@@ -93,10 +94,13 @@ class SyslogUdpHandler extends AbstractSyslogHandler
|
||||
$hostname = '-';
|
||||
}
|
||||
|
||||
$date = $this->getDateTime();
|
||||
|
||||
if ($this->rfc === self::RFC3164) {
|
||||
return "<$priority>" .
|
||||
$datetime->setTimezone(new \DateTimeZone('UTC'));
|
||||
}
|
||||
$date = $datetime->format($this->dateFormats[$this->rfc]);
|
||||
|
||||
if ($this->rfc === self::RFC3164) {
|
||||
return "<$priority>" .
|
||||
$date . " " .
|
||||
$hostname . " " .
|
||||
$this->ident . "[" . $pid . "]: ";
|
||||
|
Reference in New Issue
Block a user