title: How do I log exceptions with appropriate linebreaks using Monolog with Slim 3?
body: <pre><code>$container['logger'] = function (\Slim\Container $c) {
      $settings = $c-&gt;get('settings')['logger'];
      $logger = new Monolog\Logger($settings['name']);
      $logger-&gt;pushProcessor(new Monolog\Processor\UidProcessor());
      $logger-&gt;pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level']));
      return $logger;
  };
  
  $container['errorHandler'] = function (\Slim\Container $container) {
      return function (\Slim\Http\Request $request, \Slim\Http\Response $response, \Exception $exception) use ($container) {
          /** @var \Monolog\Logger $monoLog */
          $monoLog = $container-&gt;logger;
          $monoLog-&gt;addError((string)$exception);
  
          $response-&gt;getBody()-&gt;rewind();
          return $response-&gt;withStatus(500)
              -&gt;withHeader('Content-Type', 'text/html')
              -&gt;write("Oops, something's gone wrong!");
      };
  };
  
  $container['phpErrorHandler'] = function ($container) {
      return $container['errorHandler'];
  };
  </code></pre>
  
  <p>When ever an exception occurs I get a single line in the error log. Perhaps my memory is going fuzzy but the default PHP error logging would format things nicely on multiple lines...</p>
  
  <p>Is there a way to format it nicely? Or do I have manually format it using something like:</p>
  
  <pre><code>    $monoLog-&gt;addError($exception-&gt;getMessage());
      $monoLog-&gt;addError($exception-&gt;getTraceAsString());
      $monoLog-&gt;addError($exception-&gt;getFile());
      $monoLog-&gt;addError($exception-&gt;getCode());
      $monoLog-&gt;addError($exception-&gt;getLine());
  </code></pre>
  
  <p>Even with the above the trace appears as a single line.</p>