You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by Samuel Kerschbaumer <ke...@in.tum.de> on 2008/02/10 15:45:53 UTC

LoggerDatePatternConverter::convert regular expression

Hello.

I think there is a bug in the LoggerDatePatternConverter::convert()  
method.
In this method there is a call to ereg_replace("[^\\]u", sprintf(',% 
03d', $usecs), which should be like ereg_replace("[^\\\\]u", sprintf 
(',%03d', $usecs) instead.
The reason is that there are two quoting mechanisms in effect: The  
quoting in a PHP string and the quoting of the regexp library.
Strangely the actual call works with some of my PHP installations,  
whereas it causes trouble on others.

Could this be fixed?

Samuel

Re: LoggerDatePatternConverter::convert regular expression

Posted by Knut Urdalen <kn...@php.no>.
Samuel Kerschbaumer wrote:
> Hmm I think the purpose of this code was to support 'u' for the 
> milliseconds in the date format, since date() supports u only since 
> PHP 5.2.2.
Yes, the code is there to support milliseconds in the date format.
> Since Log4PHP now focus only on PHP5 support these lines are 
> unnecessary and should be removed.
>
After testing changing the code to use the documented "u" modifier 
directly in the date() function I realize that this won't work.

See: http://bugs.php.net/bug.php?id=42921 for details.

We can only remove the regular expression here if we can to skip support 
for a "u" modifier in our date format.

Knut


Re: LoggerDatePatternConverter::convert regular expression

Posted by Samuel Kerschbaumer <ke...@in.tum.de>.
Am 12.02.2008 um 03:19 schrieb Marshall Pierce:

> Samuel Kerschbaumer wrote:
>> Hello.
>>
>> I think there is a bug in the LoggerDatePatternConverter::convert 
>> () method.
>> In this method there is a call to ereg_replace("[^\\]u",
>> sprintf(',%03d', $usecs), which should be like ereg_replace("[^\\\ 
>> \]u",
>> sprintf(',%03d', $usecs) instead.
>> The reason is that there are two quoting mechanisms in effect: The
>> quoting in a PHP string and the quoting of the regexp library.
>> Strangely the actual call works with some of my PHP installations,
>> whereas it causes trouble on others.
>>
>> Could this be fixed?
>>
>> Samuel
>
> This handling of escaping 'u' to '\u' seems entirely unnecessary since
> php's date() already lets you escape anything you want with a '\'. Try
> deleting the extra stuff and have the method simply return the  
> output of
> date() on the date format and timestamp.
>
> -Marshall

Hmm I think the purpose of this code was to support 'u' for the  
milliseconds in the date format, since date() supports u only since  
PHP 5.2.2.
Since Log4PHP now focus only on PHP5 support these lines are  
unnecessary and should be removed.

Samuel


Re: LoggerDatePatternConverter::convert regular expression

Posted by Marshall Pierce <ma...@genius.com>.
Samuel Kerschbaumer wrote:
> Hello.
> 
> I think there is a bug in the LoggerDatePatternConverter::convert() method.
> In this method there is a call to ereg_replace("[^\\]u",
> sprintf(',%03d', $usecs), which should be like ereg_replace("[^\\\\]u",
> sprintf(',%03d', $usecs) instead.
> The reason is that there are two quoting mechanisms in effect: The
> quoting in a PHP string and the quoting of the regexp library.
> Strangely the actual call works with some of my PHP installations,
> whereas it causes trouble on others.
> 
> Could this be fixed?
> 
> Samuel

This handling of escaping 'u' to '\u' seems entirely unnecessary since
php's date() already lets you escape anything you want with a '\'. Try
deleting the extra stuff and have the method simply return the output of
date() on the date format and timestamp.

-Marshall