0

I am currently capturing script errors as such:

error_reporting(-1) ;
ini_set("log_errors",TRUE) ;
ini_set("error_log","phpErrors.log") ;

But I need a better mechanism of reporting those errors so I don't have to manually go look at log files to see if something was captured. I read about error_log has a built in email function as found here: Send errors message via email using error_log()

Does using this email function in error_log() interfere with logging to the log file? As well, is there a better mechanism for creating alerts (of some type) so I am not getting inundated with error emails? I suppose whatever mechanism I use it will be the same level of alerts/emails - but I just need a better way of getting notified than scrubbing through error logs.

Any recommendations?

rolinger
  • 2,787
  • 1
  • 31
  • 53

1 Answers1

1

When you call error_log, it will do only the action as specified by the second parameter, not both or more than one. So if you say to send an email, it won't log to disk. If the second parameter was a bitmask, that would imply that then. I'm guessing that the intention was for this to be used sporadically with explicit intent each time.

As to "Is there a better mechanism?", that gets subjective, and there is a tipping point with logging that you'll need to determine what is best for you and your project, workflow, team, etc.

Personally, I like Monolog which follows PSR-3 and documents 8 levels of logging, from debug to emergency. Using Monolog you setup "handlers" whose job is to do something with the logs, either write to disk, database, syslog, console, or possibly send an email, SMS or some other third party service. Each handler can be setup with different log levels, so you might log debug and greater to disk, send error or greater to email and emergency to SMS. The customization is completely up to you.

There are other PSR-3 loggers out there, too, and it is really trivial to roll your own if you need something simple, but I would encourage you to look into that general setup.

Chris Haas
  • 53,986
  • 12
  • 141
  • 274