Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
FuelPHP 1.8 Log newline becomes space
  • Hi,

    My company is currently using FuelPHP 1.7.3, things have been great but we plan to upgrade to version 1.8 as it supports PHP 7. 

    We have some tasks written and in local development environment which write the contents in log (i.e. \Log::info) so we can confirm that they work correctly. There are some long texts that we want to confirm in Log before putting to real test environment, but for some reasons the newlines we want to print have all been converted into spaces so by reading logs we have no idea which is newline and which is space. For example \Log::info("A\nB") would be written in log as INFO [date-time] --> A B. We did not have this in 1.7.3 and since nothing regarding this is mentioned in changelog, we just want to confirm that this is actually a feature (maybe for a reason that we have not yet be able to comprehend) and not a bug.

    Thank you for answering my question.
  • HarroHarro
    Accepted Answer
    Fuel uses Monolog for logging, and by default the LineFormatter doesn't support embedded newlines. But it has the option to enable it.

    Simplest would be to extend the Log class in your app (see the docs), and overload the initialize() method like so:

    public static function initialize()
    {
        // set up logging
        parent::initialize();

        // get the formatter used
        $handler  = static::$monolog->popHandler();
        $formatter = $handler->getFormatter();
        // enable linebreaks
        $formatter->allowInlineLineBreaks(true);
    }

    (disclaimer: from the top of my head)
  • Thanks for your information, it was very helpful but your code does not work properly so I put my working code here for reference.

    class Log extends Fuel\Core\Log {

        public static function initialize() {
            // set up logging
            parent::initialize();

            // get the formatter used
            $handler = static::$monolog->popHandler();
            $formatter = $handler->getFormatter();

            // enable linebreaks
            $formatter->allowInlineLineBreaks(true);

            // set handler
            static::$monolog->pushHandler($handler);
        }
    }
  • Ah, missed pushing it a again! Thanks for the feedback.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion