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?
AI-generated summary
In a discussion about alerting admins of errors in a custom Discourse plugin, Bas asks how to log and notify admins when recurring tasks fail. david suggests logging errors via Rails.logger.error (visible at <your forum>/logs) or sending private messages to @admins, referencing the discourse-saved-searches plugin as an example. Bas confirms interest in logging and asks how to write to error logs, wondering if raising an exception or using a Discourse.error class is needed. david clarifies that Rails.logger.info/warn/error can be used anywhere in Ruby code and notes that Discourse’s built-in admin alerts may appear as on-site warnings rather than emails. Bas is satisfied with on-site alerts. jomaxro adds that admins receive a dismissable blue bar notification at the top of the site when error thresholds are exceeded, linking to /logs — and shares a screenshot illustrating this behavior. The consensus is that logging via Rails.logger is sufficient and triggers built-in admin alerts, making additional email or PM systems optional unless more immediate or custom notifications are desired.
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? ![]()
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:
Rails.logger.info '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 ![]()
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
![]()
