0

I am developing PHP websites on my own and want to turn off displaying error messages to the browser as sites move into production. I thought about setting up Monolog but am worried that with just me developing it might be overkill and more maintenance.

I can see that errors are being recorded in /var/log/apache2/error.log and that I can use error_log(json_encode($someArray) to do debugging.

Is this approach realistic or will it be a total pain? If it is feasible are there ways of making the output from $ tail -f error.log prettier eg formatting arrays and having an empty line between each log entry? I have read about the ErrorLogFormat Directive on the Apache website but currently do not understand it very much.

user3425506
  • 1,285
  • 1
  • 16
  • 26
  • 1
    I don't know the answer, but `/var/log/apache2/error.log` is normally the default Apache HTTP Server error log. I'd advise to have a separate set of logs for each virtual host, and separate error logs for PHP. – Álvaro González Feb 20 '23 at 11:43
  • I thought there might be a utility which, as well as formatting the log entries nicely, could filter them to show just ones from a given virtual host. – user3425506 Feb 20 '23 at 11:50
  • 1
    In general a good overview: https://stackoverflow.com/questions/10331084/error-logging-in-a-smooth-way - For debugging - you could have a look at the [Symfony var-dumper](https://symfony.com/doc/current/components/var_dumper.html) - Afaik you can use it without having a Symfony project. I found it quite helpful to "dump" infos in a prod env, which only I would receive and not the user. – Uwe Feb 20 '23 at 12:18
  • 1
    You can always configure different error logs for for different virtual hosts. Also, I warn you against doing a live debugging. For a really urgent fix you can always use error_log(json_encode with tail -f. But whatever fancy debugging with ornate decorations is best to be done on a dev server. – Your Common Sense Feb 20 '23 at 14:43
  • Also, always a good idea to ask one question at a time. How to log PHP errors is one question, but how to debug on a live site and log array dumps is another. – Your Common Sense Feb 20 '23 at 14:44

0 Answers0