The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

How do I log errors to a file? Sample code provided

chris's Avatar


12 Oct, 2013 05:09 PM

  1 <?php
  2 error_reporting(E_ALL | E_STRICT);
  3 require '../vendor/autoload.php';
  4 require 'config.php';                                                                                                                                            
  7 $app = new \Slim\Slim(array(
  8     'debug' =>          false,
  9     'log.enabled' =>    true,
 10     'log.level' =>      \Slim\Log::DEBUG,
 11     'mode' =>           'development',
 12     'slim.errors' => fopen($config['root'].'app/errors_slim.log', 'w'),
 13     'view' => new \Slim\Views\Twig()
 14 ));
 16 $app->log->debug("This is a test from the logger...");
 17 $app->run();
 19 die('test');

I'm not getting any errors in errors_slim.log... Any ideas?

  1. 1 Posted by David Rodger on 20 Oct, 2013 03:46 AM

    David Rodger's Avatar

    By default, Slim writes errors to php://stderr, which as I understand it is only available to command-line scripts.

    I've not tried it, but I think you could explicitly set a "log writer" by passing a file handle in your app settings...

    $logWriter = new \Slim\LogWriter(fopen('/path/to/your/log', 'a'));
    $app = new Slim(array('log.writer' => $logWriter));
  2. 2 Posted by salva on 24 Oct, 2015 08:51 AM

    salva's Avatar

    Perfect! it works for me, thanks David

  3. 3 Posted by hema.jjbytes on 20 Nov, 2017 03:00 PM

    hema.jjbytes's Avatar

    Hi ,

        Can u please share the code , for me it is not working , i have given fopen('error.log','a');

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac