Search code examples
htmllogginglog4php

Modify/configure log4php LoggerLayoutHtml to insert <BR> tags


Sorry, rather obscure... but there doesn't appear to be a log4php forum.

I just want to log a string and for the newlines to be output in the HTML log as <br>. Trouble is, even if you use PHP's nl2br, it appears the logger reconverts back to the artefacts (or whatever the word is)... i.e. the logger converts "<br>" to "&lt;br&gt;" before outputting to the HTML file.

I don't know whether you can configure LoggerLayoutHtml to do this (clean, nice solution) or whether I will have to do some (dirty) tweaking of the code in the PHP files of log4php...


Solution

  • anyone interested in a quick and dirty solution:

    in the file LoggerLayoutHtml.php under log4php:

    replace the line

    $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES);
    

    with this:

        $rendered_msg = htmlentities( $event->getRenderedMessage(), ENT_QUOTES );
        $sbuf .= nl2br( $rendered_msg );