php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #24928 error_log inconsistent in adding newline to files
Submitted: 2003-08-04 01:07 UTC Modified: 2004-04-08 00:47 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phpbugs at localpin dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.1 OS: Windows XP Home Edition
Private report: No CVE-ID: None
 [2003-08-04 01:07 UTC] phpbugs at localpin dot com
Description:
------------
There is an inconsistency whether error_log gives a newline or not when sending output, only based upon whether the file is not named (message type 0) or named explicitly (message type 3).

i.e. when doing "error_log($msg)" a newline is automatically appended, but when doing "error_log($msg, 3, $myfile)" a newline is not automatically appended.

e.g. error_log($msg) gives:
1. My msg
2. My msg
3. My msg
4. My msg

but error_log($msg, 3, $another_file) gives:
1. My msg 2. My msg 3. M
y msg 4. My msg

Since in both cases the output is to a file, it seems to me that this is inconsistent.  Either BOTH should give an automatic newline, or NEITHER.

One can even imagine the case where the filename for both is identical (e.g. both use the file "error.log"), yet because you specify the name of the file explicitly, you don't get a 'free' newline char.

Reproduce code:
---------------
var $counter = 1;
var $log_elsewhere = true;
var $msg_prefix = "This is test number: ";
var $dev_filename = "c:/Program Files/Apache Group/Apache/logs/dev_error.log";$elsewhere_log_name = 

while (true) {
  $msg = $msg_prefix . $counter;
  if ($log_elsewhere) {
    error_log($fileline, 3, $dev_filename);

    // The following line should not be necessary
    error_log("\n", 3, $dev_filename);
  }
  else {
    error_log($fileline);
  }					

  $counter++;
}

Expected result:
----------------
Without the extra newline sending, I would like the output to be identical in both cases.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-04 01:12 UTC] phpbugs at localpin dot com
The observant reader will notice that the sample code should use the the variable $msg rather than $fileline:

error_log($msg, 3, $dev_filename);

error_log($msg);

;-)
 [2003-08-04 10:49 UTC] sniper@php.net
This is the correct and expected behaviour. Using the type '3' for logging errors is supposed to be flexible, someone might NOT want any linefeeds appended, ie. if they want to log in binary format, for example.

 [2004-04-08 00:47 UTC] irchtml@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 18:01:27 2024 UTC