How to alert admins if there is an error in a custom plugin?

We’re developing a custom plugin that has a recurring task scheduled, how should we alert admins if there are a lot of errors thrown?

You can easily write errors to the logs visible at <your forum>/logs. If you want something more visible, you could consider putting some logic in your plugin that sends a PM to @admins.

discourse-saved-searches sends automated PMs from a plugin, so that’s probably a good place to start.


How do you do this? :slight_smile:
Sorry if this sounds obtuse, I honestly searched quite a bit and can’t find anything about logging errors.
As far as I know, the system can automatically send an email if there is too much logging, so that would actually be sufficient for our case.

How do I post into the error log? Just raise an error? Or is there a specific Discourse.error class?

To write to the logs, you should be able to do this from anywhere in ruby: 'An info message'
Rails.logger.warn 'A warning message'
Rails.logger.error 'An error message'

I haven’t looked at those “alert admins” settings before, so not sure exactly how they work. I think they give admin users a warning on the site itself, rather than sending an email, but I could be wrong.


I’m a forum junkie, so that’s fine :slight_smile:

1 Like

We use those here. Essentially you get a small, dismissable blue bar along the top of the site that says something like “xyz in last hour exceeds site setting limit of xxx/hour”. The bar links to /logs.

Edit: Here’s a screenshot