title: Slim framework Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Cannot create LogWriter
body: <p>I recently started using Slim framework. I am currently attempting to authenticate using Middleware. This is the where the middleware is called:</p>
  
  <pre><code>$app-&gt;post('/profile', 'authenticate', function () {
       // code here
  }
  </code></pre>
  
  <p>This is where my middleware takes care of the authentication:</p>
  
  <pre><code>function authenticate(\Slim\Route $route) {
      // Getting request headers
      $headers = apache_request_headers();
      $response = array();
      $app = \Slim\Slim::getInstance();
  
      // Verifying Authorization Header
      if (isset($headers['Authorization'])) {
          $db = new DbHandler();
  
          // get the api key
          $api_key = $headers['Authorization'];
          // validating api key
          if (!$db-&gt;isValidApiKey($api_key)) {
              // api key is not present in users table
              $response["error"] = true;
              $response["message"] = "Access Denied. Invalid Api key";
              echoRespnse(401, $response);
              $app-&gt;stop();
          } else {
              global $user_id;
              // get user primary key id
              $user_id = $db-&gt;getUserId($api_key);
          }
      } else {
          // api key is missing in header
          $response["error"] = true;
          $response["message"] = "Api key is misssing";
          echoRespnse(400, $response);
          $app-&gt;stop();
      }
  };
  </code></pre>
  
  <p>I receive this error when I attempt the POST call. Other calls not requiring authentication all work correctly.</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Cannot create LogWriter. Invalid resource handle.' in D:\Liftmo\Liftmo.com\api\Slim\LogWriter.php:60 Stack trace: #0 D:\Liftmo\Liftmo.com\api\Slim\Slim.php(191): Slim\LogWriter->__construct(false) #1 D:\Liftmo\Liftmo.com\api\Slim\Helper\Set.php(228): Slim\Slim->Slim{closure}(Object(Slim\Helper\Set)) #2 D:\Liftmo\Liftmo.com\api\Slim\Helper\Set.php(88): Slim\Helper\Set->Slim\Helper{closure}(Object(Slim\Helper\Set)) #3 D:\Liftmo\Liftmo.com\api\Slim\Helper\Set.php(185): Slim\Helper\Set->get('logWriter') #4 D:\Liftmo\Liftmo.com\api\Slim\Slim.php(196): Slim\Helper\Set->offsetGet('logWriter') #5 D:\Liftmo\Liftmo.com\api\Slim\Helper\Set.php(228): Slim\Slim->Slim{closure}(Object(Slim\Helper\Set)) #6 D:\Liftmo\Liftmo.com\api\Slim\Helper\Set.php(88): Slim\Helper\Set->Slim\Helper{closure}(Object(Slim\Helper\Set)) #7 D:\Liftmo\Liftmo.com\api\Slim\Slim.php(234): Slim\Helper\Set->get('log') #8 D:\Liftmo\Liftmo.com\api\Slim\Slim.php(402): Slim\Slim->__get('log') in D:\Liftmo\Liftmo.com\api\Slim\LogWriter.php on line 60</p>
  </blockquote>
  
  <p>I've run through the code line by line and it seems the issue lies with the line</p>
  
  <pre><code>$db = new DbHandler();
  </code></pre>
  
  <p>I'm pretty confused though because the class was used without issue everywhere else in my code.</p>
  
  <pre><code>require_once 'include/DbHandler.php'; // DbHandler included here at the top
  </code></pre>
  
  <p>I'd really appreciate it if someone could help me out. I took the authentication from <a href="http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-23/" rel="nofollow">HERE</a>. Literally could not find this issue resolved anywhere. Using Google App Engine with Cloud SQL to deploy. </p>