I have set up log4php to log to a file using the LoggerAppenderRollingFile appender and the LoggerLayoutTTCC layout. When I log an exception, however, it doesn't display the exception details such as the stack trace like I'm used to seeing in log4net.
I've had a quick look through the code and it looks like the LoggerAppenderMongoDB has support for displaying exceptions with the formatThrowable
method, but I don't see anything similar in the other appenders.
I feel like I am missing something obvious. Is there something that I need to configure in order to print these details to the log file? Do I need to create a custom LoggerAppender class? Or can these be done with a different layout or a custom renderer?
FYI, now that LoggerLayoutTTCC
is deprecated, you can use LoggerLayoutPattern with a better format string to include exceptions.
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%d{m/d/y H:i:s,u} [%t] %p %c %x - %m %newline%throwable" />
</layout>
<!-- %newline%throwable is the important part -->
See the Logging Exceptions section of the docs: http://logging.apache.org/log4php/docs/layouts/pattern.html#Logging_exceptions
You should use PHP set_exception_handler function and wrap log4php using this function. check it out at: http://php.net/manual/en/function.set-exception-handler.php
function exception_handler($exception) {
$log->debug($exception->getMessage()); }
set_exception_handler('exception_handler');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With