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 "Till Heimann (JIRA)" <ji...@apache.org> on 2012/09/04 16:42:07 UTC

[jira] [Created] (LOG4PHP-187) Logging does not work in shutdown function

Till Heimann created LOG4PHP-187:
------------------------------------

             Summary: Logging does not work in shutdown function
                 Key: LOG4PHP-187
                 URL: https://issues.apache.org/jira/browse/LOG4PHP-187
             Project: Log4php
          Issue Type: Bug
    Affects Versions: 2.2.1
         Environment: Linux x86_64 GNU/Linux with PHP 5.4.14,
Windows 7 with PHP 5.4.6
            Reporter: Till Heimann


I register a shutdown function in php. In this shutdown function I try to log something unsing Log4php.

actual:
No Log entries for any log call within the shutdown function.

expected:
Log entries from the shutdown function.


Exemple Code, config file and shell output:
****** log4php_conf.xml *******
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://logging.apache.org/log4php/">
        <appender name="myAppender" class="LoggerAppenderFile">
                <layout class="LoggerLayoutTTCC" />
                <param name="file" value="test.log" />
        </appender>
        <root>
                <level value="TRACE" />
                <appender_ref ref="myAppender" />
        </root>
</configuration>

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

******* test.php *******
<?php

require_once './log4php/Logger.php';

Logger::configure('./log4php_conf.xml');

$logger = Logger::getLogger("ShutdownTest");

main();


function main() {
        global $logger;
        $logger->trace("function main() called");
        $logger->info("*** start shutdown test ***");
        register_shutdown_function('shutdown');
        print("\ndo something ... ");
        sleep(1);
        print("done\n");
}


function shutdown(){
        global $logger;
        $logger->trace("function shutdown() called");
        // do some stuff like logging errors ...
        $logger->info("*** exiting shutdown test ***");
        print("This line is printed out.\n");
}
?>

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

Linux output:
-bash-3.2$ php test.php

do something ... done
This line is printed out.
-bash-3.2$ cat test.log
Tue Sep  4 14:40:46 2012,948 [29482] TRACE ShutdownTest - function main() called
Tue Sep  4 14:40:46 2012,952 [29482] INFO ShutdownTest - *** start shutdown test ***
-bash-3.2$ php --version
PHP 5.2.14 (cli) (built: Aug 27 2010 16:44:17)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

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

Windows output:
PS C:\test_log4php> php .\test.php

do something ... done
This line is printed out.
PS C:\test_log4php> cat .\test.log
09/04/12 14:13:05,118 [4844] TRACE ShutdownTest - function main() called
09/04/12 14:13:05,120 [4844] INFO ShutdownTest - *** start shutdown test ***
PS C:\test_log4php> php --version
PHP 5.4.6 (cli) (built: Aug 15 2012 21:16:03)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
PS C:\test_log4php>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LOG4PHP-187) Logging does not work in shutdown function

Posted by "Till Heimann (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-187?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13452935#comment-13452935 ] 

Till Heimann commented on LOG4PHP-187:
--------------------------------------

OK, the log4php Version from trunk also works in both mentioned environments.

Thanks.
                
> Logging does not work in shutdown function
> ------------------------------------------
>
>                 Key: LOG4PHP-187
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-187
>             Project: Log4php
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: Linux x86_64 GNU/Linux with PHP 5.4.14,
> Windows 7 with PHP 5.4.6
>            Reporter: Till Heimann
>
> I register a shutdown function in php. In this shutdown function I try to log something unsing Log4php.
> actual:
> No Log entries for any log call within the shutdown function.
> expected:
> Log entries from the shutdown function.
> Exemple Code, config file and shell output:
> ****** log4php_conf.xml *******
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration xmlns="http://logging.apache.org/log4php/">
>         <appender name="myAppender" class="LoggerAppenderFile">
>                 <layout class="LoggerLayoutTTCC" />
>                 <param name="file" value="test.log" />
>         </appender>
>         <root>
>                 <level value="TRACE" />
>                 <appender_ref ref="myAppender" />
>         </root>
> </configuration>
> ---------------------------------------------------------------------
> ******* test.php *******
> <?php
> require_once './log4php/Logger.php';
> Logger::configure('./log4php_conf.xml');
> $logger = Logger::getLogger("ShutdownTest");
> main();
> function main() {
>         global $logger;
>         $logger->trace("function main() called");
>         $logger->info("*** start shutdown test ***");
>         register_shutdown_function('shutdown');
>         print("\ndo something ... ");
>         sleep(1);
>         print("done\n");
> }
> function shutdown(){
>         global $logger;
>         $logger->trace("function shutdown() called");
>         // do some stuff like logging errors ...
>         $logger->info("*** exiting shutdown test ***");
>         print("This line is printed out.\n");
> }
> ?>
> ---------------------------------------------------------------------
> Linux output:
> -bash-3.2$ php test.php
> do something ... done
> This line is printed out.
> -bash-3.2$ cat test.log
> Tue Sep  4 14:40:46 2012,948 [29482] TRACE ShutdownTest - function main() called
> Tue Sep  4 14:40:46 2012,952 [29482] INFO ShutdownTest - *** start shutdown test ***
> -bash-3.2$ php --version
> PHP 5.2.14 (cli) (built: Aug 27 2010 16:44:17)
> Copyright (c) 1997-2010 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
> ---------------------------------------------------------------------
> Windows output:
> PS C:\test_log4php> php .\test.php
> do something ... done
> This line is printed out.
> PS C:\test_log4php> cat .\test.log
> 09/04/12 14:13:05,118 [4844] TRACE ShutdownTest - function main() called
> 09/04/12 14:13:05,120 [4844] INFO ShutdownTest - *** start shutdown test ***
> PS C:\test_log4php> php --version
> PHP 5.4.6 (cli) (built: Aug 15 2012 21:16:03)
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
> PS C:\test_log4php>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Closed] (LOG4PHP-187) Logging does not work in shutdown function

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-187?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ivan Habunek closed LOG4PHP-187.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.3.0
         Assignee: Ivan Habunek

Cool. Closing issue.
                
> Logging does not work in shutdown function
> ------------------------------------------
>
>                 Key: LOG4PHP-187
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-187
>             Project: Log4php
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: Linux x86_64 GNU/Linux with PHP 5.4.14,
> Windows 7 with PHP 5.4.6
>            Reporter: Till Heimann
>            Assignee: Ivan Habunek
>             Fix For: 2.3.0
>
>
> I register a shutdown function in php. In this shutdown function I try to log something unsing Log4php.
> actual:
> No Log entries for any log call within the shutdown function.
> expected:
> Log entries from the shutdown function.
> Exemple Code, config file and shell output:
> ****** log4php_conf.xml *******
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration xmlns="http://logging.apache.org/log4php/">
>         <appender name="myAppender" class="LoggerAppenderFile">
>                 <layout class="LoggerLayoutTTCC" />
>                 <param name="file" value="test.log" />
>         </appender>
>         <root>
>                 <level value="TRACE" />
>                 <appender_ref ref="myAppender" />
>         </root>
> </configuration>
> ---------------------------------------------------------------------
> ******* test.php *******
> <?php
> require_once './log4php/Logger.php';
> Logger::configure('./log4php_conf.xml');
> $logger = Logger::getLogger("ShutdownTest");
> main();
> function main() {
>         global $logger;
>         $logger->trace("function main() called");
>         $logger->info("*** start shutdown test ***");
>         register_shutdown_function('shutdown');
>         print("\ndo something ... ");
>         sleep(1);
>         print("done\n");
> }
> function shutdown(){
>         global $logger;
>         $logger->trace("function shutdown() called");
>         // do some stuff like logging errors ...
>         $logger->info("*** exiting shutdown test ***");
>         print("This line is printed out.\n");
> }
> ?>
> ---------------------------------------------------------------------
> Linux output:
> -bash-3.2$ php test.php
> do something ... done
> This line is printed out.
> -bash-3.2$ cat test.log
> Tue Sep  4 14:40:46 2012,948 [29482] TRACE ShutdownTest - function main() called
> Tue Sep  4 14:40:46 2012,952 [29482] INFO ShutdownTest - *** start shutdown test ***
> -bash-3.2$ php --version
> PHP 5.2.14 (cli) (built: Aug 27 2010 16:44:17)
> Copyright (c) 1997-2010 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
> ---------------------------------------------------------------------
> Windows output:
> PS C:\test_log4php> php .\test.php
> do something ... done
> This line is printed out.
> PS C:\test_log4php> cat .\test.log
> 09/04/12 14:13:05,118 [4844] TRACE ShutdownTest - function main() called
> 09/04/12 14:13:05,120 [4844] INFO ShutdownTest - *** start shutdown test ***
> PS C:\test_log4php> php --version
> PHP 5.4.6 (cli) (built: Aug 15 2012 21:16:03)
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
> PS C:\test_log4php>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LOG4PHP-187) Logging does not work in shutdown function

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-187?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13447764#comment-13447764 ] 

Ivan Habunek commented on LOG4PHP-187:
--------------------------------------

Hello Till,

I noticed this behaviour some weeks ago and fixed it. The cause of the problem was that log4php appenders were using register_shutdown_function, instead of using a destructor, in hope of exiting gracefully in case of a fatal error. Shutdown functions are executed even if a fatal error occurs, and destructors are not. However, it caused the bug you are now reporting.

Luckily, this is fixed in trunk. I have tried it out, and the ouput is:

ihabunek@vs1779:~/tmp$ cat test.log
Tue Sep  4 17:38:38 2012,715 [30453] TRACE ShutdownTest - function main() called
Tue Sep  4 17:38:39 2012,187 [30453] INFO ShutdownTest - *** start shutdown test ***
Tue Sep  4 17:38:40 2012,187 [30453] TRACE ShutdownTest - function shutdown() called
Tue Sep  4 17:38:40 2012,187 [30453] INFO ShutdownTest - *** exiting shutdown test ***

Please try for yourself and let me know if it works. To get the latest code, just run:
svn checkout https://svn.apache.org/repos/asf/logging/log4php/trunk/src/main/php log4php

Thanks for reporting.
                
> Logging does not work in shutdown function
> ------------------------------------------
>
>                 Key: LOG4PHP-187
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-187
>             Project: Log4php
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: Linux x86_64 GNU/Linux with PHP 5.4.14,
> Windows 7 with PHP 5.4.6
>            Reporter: Till Heimann
>
> I register a shutdown function in php. In this shutdown function I try to log something unsing Log4php.
> actual:
> No Log entries for any log call within the shutdown function.
> expected:
> Log entries from the shutdown function.
> Exemple Code, config file and shell output:
> ****** log4php_conf.xml *******
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration xmlns="http://logging.apache.org/log4php/">
>         <appender name="myAppender" class="LoggerAppenderFile">
>                 <layout class="LoggerLayoutTTCC" />
>                 <param name="file" value="test.log" />
>         </appender>
>         <root>
>                 <level value="TRACE" />
>                 <appender_ref ref="myAppender" />
>         </root>
> </configuration>
> ---------------------------------------------------------------------
> ******* test.php *******
> <?php
> require_once './log4php/Logger.php';
> Logger::configure('./log4php_conf.xml');
> $logger = Logger::getLogger("ShutdownTest");
> main();
> function main() {
>         global $logger;
>         $logger->trace("function main() called");
>         $logger->info("*** start shutdown test ***");
>         register_shutdown_function('shutdown');
>         print("\ndo something ... ");
>         sleep(1);
>         print("done\n");
> }
> function shutdown(){
>         global $logger;
>         $logger->trace("function shutdown() called");
>         // do some stuff like logging errors ...
>         $logger->info("*** exiting shutdown test ***");
>         print("This line is printed out.\n");
> }
> ?>
> ---------------------------------------------------------------------
> Linux output:
> -bash-3.2$ php test.php
> do something ... done
> This line is printed out.
> -bash-3.2$ cat test.log
> Tue Sep  4 14:40:46 2012,948 [29482] TRACE ShutdownTest - function main() called
> Tue Sep  4 14:40:46 2012,952 [29482] INFO ShutdownTest - *** start shutdown test ***
> -bash-3.2$ php --version
> PHP 5.2.14 (cli) (built: Aug 27 2010 16:44:17)
> Copyright (c) 1997-2010 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
> ---------------------------------------------------------------------
> Windows output:
> PS C:\test_log4php> php .\test.php
> do something ... done
> This line is printed out.
> PS C:\test_log4php> cat .\test.log
> 09/04/12 14:13:05,118 [4844] TRACE ShutdownTest - function main() called
> 09/04/12 14:13:05,120 [4844] INFO ShutdownTest - *** start shutdown test ***
> PS C:\test_log4php> php --version
> PHP 5.4.6 (cli) (built: Aug 15 2012 21:16:03)
> Copyright (c) 1997-2012 The PHP Group
> Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
> PS C:\test_log4php>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira