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

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.