Output

The Slim application’s environment will always contain a key slim.errors with a value that is a writableresource to which log and error messages may be written. The Slim application’s log object will write log messagesto slim.errors whenever an Exception is caught or the log object is manually invoked.

If you want to redirect error output to a different location, you can define your own writable resource bymodifying the Slim application’s environment settings. I recommend you use middleware to update the environment:

  1. <?php
  2. class CustomErrorMiddleware extends \Slim\Middleware
  3. {
  4. public function call()
  5. {
  6. // Set new error output
  7. $env = $this->app->environment;
  8. $env['slim.errors'] = fopen('/path/to/output', 'w');
  9. // Call next middleware
  10. $this->next->call();
  11. }
  12. }

Remember, slim.errors does not have to point to a file; it can point to any valid writable resource.