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
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