Jump to content

Send out email on exceptions


Dennis Spohr
 Share

Recommended Posts

Hi all,

with 

$config->adminEmail

it's possible to send out an email for fatal errors (for example a syntax-error).

It would be nice to get also an email in case of an unhandled exception. There could be a situation of an wrong upload and exceptions on the live-page.

Is this possible?

Also it could be a very handy feature to be able to choose specific logs which are sent our via email automatically.

Thanks for your feedback,
Dennis

Link to comment
Share on other sites

38 minutes ago, heldercervantes said:

Pretty sure you can add a hook somewhere, catch the errors you want and send out an email.

This would make great module though. Perhaps with the option to get a weekly digest of the log action. That'd be nice.

How can I find such a hook? I don't have much experience with them yet.
Very nice idea regarding weekly emails! 

 

36 minutes ago, adrian said:

TracyDebugger's "production" mode has the option to email for various error types.

https://processwire.com/blog/posts/introducing-tracy-debugger/#production-mode-error-logging-and-email-notification

Wow nice module, didn't see this one before. I will check it out for sure. Thank you!

  • Like 1
Link to comment
Share on other sites

Hi @Dennis Spohr,

most things can be done with hooks. Hooks are class methods that have 3 preceding underscores, so you may find them in the php and module files in the wire folder. (Using a "search-in-files" function of your Editor / IDE: "function ___"). Or go to Captain-Hook.

Unfortunately or Fortunately, the part with sending emails on exceptions / errors seems to be completly different. It uses the native PHP register_shutdown_function, done in WireShutdown.php and therefore is not hookable through the PW system.

But the PHP docs say that it is possible to register more than one shutdown-function, and that all functions get called on shutdown. So you can register your own one. If you want to have the ability to optionally bypass processwires shutdown function, you must register yours before PWs one. (I don't know how, but would try it in site/config.php first). Than, in cases where you don't want PWs function get called, you can exit yours with exit();. Otherwise other registered functions get called and executed too.

Have a read in the WireShutdown::shutdown() function. There you see how to check if there were an error, how to get it and how to inspect it, etc.

-----

Also there is the site/finished.php file, that gets executed at the end. But this one I haven't used til now and don't know if it get called on exceptions too.

-----

If you test and further questions apear, come back and ask. :)

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...