Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know this is an old question, but I ran into it too and I want to share my solution.</p> <p>The brackets at the end of log lines are due to how Monolog's <code>LineFormatter</code> tries to <code>json_encode()</code> the data in <code>%extra%</code>. The brackets are a JSON representation of an empty array.</p> <p>To turn off those brackets, I ended up having to subclass <code>Monolog\Formatter\LineFormatter</code> with my own class and overwrite its <code>convertToString($data)</code> function so it returns an empty string if there's no data present. Here's my new subclass:</p> <pre><code>namespace My\Fancy\Monolog; use Monolog\Formatter\LineFormatter; class LineFormatter extends LineFormatter { protected function convertToString($data) { if (null === $data || is_scalar($data)) { return (string) $data; } // BEGIN CUSTOM CODE - This section added to prevent empty // brackets from appearing at the end of log lines: if ((is_array($data) &amp;&amp; !$data) || is_object($data) &amp;&amp; !get_object_vars($data)) { return ''; } // END CUSTOM CODE $data = $this-&gt;normalize($data); if (version_compare(PHP_VERSION, '5.4.0', '&gt;=')) { return $this-&gt;toJson($data); } return str_replace('\\/', '/', json_encode($data)); } } </code></pre> <p>You can use this class by injecting an instance of it into your Monolog handler class, like so:</p> <pre><code>$handler = new Monolog\Handler\StreamHandler('/path/to/my/logfile', 'debug'); $handler-&gt;setFormatter(new My\Fancy\Monolog\LineFormatter()); $monolog-&gt;pushHandler($handler); </code></pre> <p>Enjoy!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload