phpapachelogginglog4php

What purpose does a PHP logging framework serve?


I've been looking for a Php logging framework throughout the web and I realized What is the need to use a PHP logging framework if Apache logs all interactions to the server?


Solution

  • 1. Fine grain control over error messages

    Relying on PHP to log all of its error in its error log, and Apache to log all its error in its error log is fine - but sometimes you need more details. For instance, something may throw an exception regarding a failed SQL query and the message might say something like SQLException: Could not retrieve XYZ data. However, we would also want to see the stack trace and SQL query that failed. We could opt to throw that in the exception message, but that deprives us of the fine grain control - I /don't always want that debugging detail.

    2. Non-web Apache related tasks

    I use PHP quite often for the CLI capabilities for cronjobs. Apache wouldn't be involved in this, and PHP would opt to send output to STDOUT. Logging any errors would allow me to review them later.

    3. Logging things that aren't errors

    I can imagine a scenario where you would want to see login times, but don't want to store it in the database. For instance:

    8/21/16 7:48 - HPierce logged in

    8/21/16 7:49 - HPierce logged out

    These aren't errors, and parsing through Apache's access logs isn't practical to get this kind of user information.