Edit report at https://bugs.php.net/bug.php?id=60599&edit=1

 ID:                 60599
 Updated by:         der...@php.net
 Reported by:        roberto at spadim dot com dot br
 Summary:            ADD DATE TIME FOR CONSOLE WARNINGS
 Status:             Open
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   any
 PHP Version:        5.4.0RC3
 Block user comment: N
 Private report:     N

 New Comment:

Just use syslog for this. PHP can log errors to it and it will add the time and 
date for you.


Previous Comments:
------------------------------------------------------------------------
[2011-12-23 07:38:53] roberto at spadim dot com dot br

yes, that´s what i´m doing today
but in any console based php script is interesting to use it, a default 
configuration to console and apache could help a lot
today i add a file at every script i start in console with this function
it´s works, but maybe at php source could be more 'beautiful' and user friendly

------------------------------------------------------------------------
[2011-12-23 07:32:42] anon at anon dot anon

Apart from fatal errors that won't call the custom handler, you can do this 
yourself via set_error_handler:

set_error_handler(function($n, $str, $file, $line, $context) {
        if ($n & error_reporting()) {
                if ($n == E_WARNING || $n == E_USER_WARNING) $type = 'Warning';
                else if ($n == E_NOTICE || $n == E_USER_NOTICE) $type = 
'Notice';
                else if ($n == E_STRICT) $type = 'Strict standards';
                else $type = 'Error';
                fwrite(STDERR,
                        $type . ': [' . date('Y-m-d H:i:s T') . ']: ' . $str .
                        ' in ' . $file . ' on line ' . $line . PHP_EOL
                );
        }
});

------------------------------------------------------------------------
[2011-12-23 05:59:17] roberto at spadim dot com dot br

Description:
------------
hi guys, i´m running a console program, it never ends just when computer is 
restarted
my problem is...
some times php show a error (warning) like this:
Warning: mysql_ping(): MySQL server has gone away in 
/home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 
982

the problem is... when it happened?
a good help could be a function like this:
error_messages_show_date_time($date_time_yes_no,$program_uptime)
to select if add or not date time, for example..

error_messages_show_date_time(1,0)
Warning: [2011-12-23 03:55:00 BRST] mysql_ping(): MySQL server has gone away in 
/home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 
982

error_messages_show_date_time(0,0)
Warning: mysql_ping(): MySQL server has gone away in 
/home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 
982

AND the second option could be:
error_messages_show_date_time(0,1)
Warning: [123455 seconds uptime] mysql_ping(): MySQL server has gone away in 
/home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 
982

error_messages_show_date_time(1,1)
Warning: [2011-12-23 03:55:00 BRST, 123455 seconds uptime] mysql_ping(): MySQL 
server has gone away in 
/home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 
982


:) this help a lot!! for web pages it´s not a big diference... just for 
console based programs

Test script:
---------------
any program with erros or warnings some thing like this could work:
<?php
error_messages_show_date_time(0,0);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt";);
sleep(10);
error_messages_show_date_time(0,1);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt";);
sleep(10);
error_messages_show_date_time(1,0);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt";);
sleep(10);
error_messages_show_date_time(1,1);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt";);
?>

Expected result:
----------------
at request descrition...

Actual result:
--------------
just warning without date time and program uptime


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60599&edit=1

Reply via email to