Questions about logging in PHP

As I said in a previous message, for development I have: error_reporting(E_ALL | E_STRICT)

When I looked at, I found: Log_errors boolean
This just seems to set this to false. So if I leave the boolean out of the setting, does that mean all errors get logged? Since the live site is hosted, is there a way to define where the log is stored (with several on the same server, it would be nice to separate them)? Can I change the amount or type of errors that are logged?

There are basically four ini settings involved in error logging (well, probably more, but these three control the basic setup).

  • error_reporting - what do you want to report, i.e., which error levels do you want to report
  • display_errors - do you want to show the errors on the screen, i.e., in the browser. Useful for development, bad idea for production.
  • log_errors - do you want to log errors to a file (On or Off).
  • error_log - of log_errors is set to On, where do you want to log the errors (in a file, in the syslog, etc). If log_errors is set to ‘Off’ this setting doesn’t do anything.

These settings don’t influence one another. So if I set display_errors to On, this does not change my value of error_reporting. Similarly, if I change the value of log_errors, this also does not change the value of error_reporting.

Every time I ask a simple question, you folks give me lots of information to study. :slight_smile:

I have done more reading on these entries.

Would I be better to use error_reporting(-1) or error_reporting(E_ALL | E_STRICT)? Is there a difference?

For log_errors, would I actually use on/off or 0/1? The page I found on gave log_errors boolean.

For error_log would I gust give the folder I want the log to be located, or give a specific file name like: error_log errors.log

For display_errors, the only requirement I found was string. Is there a list of words that work with this? Could I use display_errors screen? has a lot of information, but some examples would help on those pages.

At this moment these are exactly the same. However, this may change in the future.
-1 is “All errors, always”, and E_ALL | E_STRICT will currently also show all errors (since those two encompass all error levels there currently are).
The difference is that -1 also includes error levels that are not currently there yet. So suppose (and this is just an example) that php decided they wanted an extra level like E_SUPER_STRICT and not include this in E_ALL, you’d have the change E_ALL | E_STRICT to E_ALL | E_STRICT | E_SUPER_STRICT.
With -1 you don’t have to change anything, because it already includes everything, always.

In the .ini you use on/off. With [fphp]ini_set[/fphp] you’d use use 0/1, or true/false. This goes for all php ini Boolean directives AFAIK.

You’d give the complete path: /path/to/my/logfile.log, or a string like ‘syslog’ which will log the systems logger (/var/log/syslog on *nix, the event logger in windows)

It’s actually a boolean with an extra value. The value is either “On”, “Off” or “stderr”. That last value is only of help when running PHP on the command line, and doesn’t do anything when running from a webserver.

If you a local setup like MAMP or WAMP or something, just toy around a bit with these values to get a feel for them. Theory only gets you so far :slight_smile:

Thanks for the great help. I now have enough knowledge/understanding to really start making a mess. :slight_smile:
I know that when I get in a real mess, I can get pointed in the right direction here.

For a little bit more understanding for those that are following along, The error reporting is a Bitwise AND comparison.

So… simplify it a bit.
1 = warn
2 = error
4 = fatal
8 = supererror (something i made up)

So, E_WARN would be defined as 0001 (intval 1). We could define E_SERIOUS as 0110 (6). E_ALL as 1111 (15).
Why -1? Because integers are signed, and (lets say) 8 bits long (1 byte, for simplicity’s sake. I know int numbers are usually much longer.)
So our numbers are actually
0000 0001
0000 0110
0000 1111

If our script throws a Warning, it does an AND with our defined reporting level (lets say we did E_SERIOUS [0000 0110]), and it’s report level (warning = 0000 0001 = 1). 0000 0110 & 0000 0001 = 0000 0000 (if you dont get this part, google ‘bitwise and’). The result = 0, so we do not report the error.

We’ve got 3 unused bits (16,32, and 64. 128 is the sign bit, because it is the highest order bit in our number). So we could add a new value, 16 - ultraerror. Now our E_ALL doesnt catch that (0001 0000 AND 0000 1111 = 0000 0000).
-1, however, is represented as 1111 1111 - it truly would catch everything.