title: Error logging, in a smooth way
body: <p>I've been reading on in particular 'error logging' And I have come up with the function 'error_log' which seem to be a good tool to use to handle the error logging. But how is the smoothest and best way to use it?</p>
  
  <p>If I have a </p>
  
  <pre><code>try {
       //try a database connection...
  
  } catch (PDOException $e) {
      error_log($e-&gt;getMessage(), 3, "/var/tmp/my-errors.log");
  
  }
  </code></pre>
  
  <p>This would log the error in the my-errors.log file. But what If I sometime need to change the position of where the file is, a new folder, or something. If I have tons of files I need to change them all.</p>
  
  <p>Now I started of thinking to use a variable to set the path to the error log. Sure that could work, but what If I want to use the error_log in a function or class method? Then I would need to set the variable as global, but that is considered bad practise! But what If I shouldn't use the function deep in a class, wouldn't that also be considered bad practise? What is a good solution here?</p>
  
  <pre><code>&lt;?php
  
  function legit() {
      try {
          if (1 == 1) {
              throw new Exception('There was an error here');
          }
      } catch (Exception $e) {
          throw new Exception('throw the error to the try-catch outside the function...');
      }
  
  }
  
  try {
      legit();
  } catch (Exception $e) {
      echo 'error here' . $e-&gt;getMessage();
  
      //log it
  }
  </code></pre>
  
  <p>This is an example of what I was talking about above (Not having the logging deep in a class/function... Is it a good way?)</p>
  
  <p>Furtheron:</p>
  
  <p>I am not quite sure how I should use the Exceptions in general. Let's say I want to do a INSERT to a database with SQL inside a method, would I use a try/catch and then rethrow the exception if it fails? Is that considered good practise? Examples please.</p>