php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77913 error_log via syslog: PHP will split msg on line break
Submitted: 2019-04-16 17:35 UTC Modified: 2019-06-17 11:17 UTC
From: whissi at whissi dot de Assigned: ab (profile)
Status: Closed Package: *General Issues
PHP Version: 7.3.4 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: whissi at whissi dot de
New email:
PHP Version: OS:

 

 [2019-04-16 17:35 UTC] whissi at whissi dot de
Description:
------------
PHP 7.3 introduced "syslog.filter" to control content send to syslog.
According to documentation (https://www.php.net/manual/en/errorfunc.configuration.php#ini.syslog.filter), "syslog.filter=all" should allow all characters (=same behavior like in PHP 7.2 or before). However, even when set "syslog.filter=all" to allow all characters including line breaks, when you now send a multi-line message via error_log() through syslog, PHP splits message on line break so you end up with multiple messages instead of sending one single message like before.

Test script:
---------------
<?php
$message = "This is line #1" . PHP_EOL;
$message .= "This is line #2";

$iniSetting = ini_get('error_log');
if ($iniSetting !== 'syslog') {
	die("You must set error_log=syslog!");
}

if (version_compare(phpversion(), '7.3', '>')) {
	$iniSetting = ini_get('syslog.filter');
	if ($iniSetting !== 'all') {
		die("You must set syslog.filter=all!");
	}
}

error_log($message);

print "Now please review your syslog!" . PHP_EOL;


Expected result:
----------------
When running test script like

> /usr/bin/php7.3 -d error_log=syslog -d syslog.filter=all test.php

I would expect one single syslog message like

> Apr 16 16:52:06 myhost php: This is line #1#012This is line #2

Actual result:
--------------
I am getting _two_ messages:

> Apr 16 16:53:20 myhost php: This is line #1
> Apr 16 16:53:20 myhost php: This is line #2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-16 17:40 UTC] whissi at whissi dot de
Even with "syslog.filter=no-ctrl" when you would expect a syslog message like

> Apr 16 16:54:09 myhost php: This is line #1This is line #2

because PHP has filtered control chars like line break, you end up with two messages, so filtering doesn't work as expected.
 [2019-04-16 19:36 UTC] requinix@php.net
Isn't it a good thing that the line break is being recognized and handled?
 [2019-04-16 19:43 UTC] whissi at whissi dot de
Not when this is a backward incompatible change.

Of course, if this was a desired change, please add it to https://www.php.net/manual/en/migration73.incompatible.php and in addition please provide a way to send multi-line messages.
 [2019-04-16 19:49 UTC] whissi at whissi dot de
And if this was a desired change, maybe rename "syslog.filter=no-ctrl" to "syslog.filter=no-ctrl-but-line-breaks" :-)

I.e. you either _filter_ all ctrl chars like the option says or none. But filtering some but handle/interpret others isn't good.
 [2019-04-16 21:42 UTC] requinix@php.net
-Assigned To: +Assigned To: ab
 [2019-04-16 21:42 UTC] requinix@php.net
https://github.com/php/php-src/commit/a1f3a0105d885879102d366de506c353a75c8d04

I think the newline treatment is a good thing and probably what the average developer would expect to happen, BC break or not, so IMO this should be a doc bug.
 [2019-04-16 22:30 UTC] spam2 at rhsoft dot net
> I think the newline treatment is a good thing and probably 
> what the average developer would expect to happen

for sure not, i would expect and code that in a away that the new line is replaced by a space because grep and friends don't work very nice with magically wrapped lines
 [2019-06-17 11:17 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-06-17 11:17 UTC] nikic@php.net
https://github.com/php/php-src/pull/4265 adds a new syslog.filter=raw option to not process syslog messages at all -- newlines will be passed through as is.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC