appprefix = $appprefix; $this->hostname = php_uname( 'n' ); } protected function syslogHeader( $severity, $app ) { $pri = $severity + $this->facility; // Goofy date format courtesy of RFC 3164 :( // RFC 3164 actually specifies that the day of month should be space // padded rather than unpadded but this seems to work with rsyslog and // Logstash. $timestamp = date( 'M j H:i:s' ); return "<{$pri}>{$timestamp} {$this->hostname} {$app}: "; } private function splitMessageIntoLines( $message ): array { if ( is_array( $message ) ) { $message = implode( "\n", $message ); } return preg_split( '/$\R?^/m', (string)$message, -1, PREG_SPLIT_NO_EMPTY ); } protected function write( array $record ) { $lines = $this->splitMessageIntoLines( $record['formatted'] ); $header = $this->syslogHeader( $this->logLevels[$record['level']], $this->appprefix . $record['channel'] ); foreach ( $lines as $line ) { $this->socket->write( $line, $header ); } } }