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

**URL:** https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364
**Category:** Development
**Created:** [9월 19, 2017, 1:44오후 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364 "2017-09-19T13:44:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [9월 19, 2017, 1:44오후 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364/1 "2017-09-19T13:44:51Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [9월 19, 2017, 2:18오후 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364/2 "2017-09-19T14:18:47Z")

</div>

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](https://github.com/discourse/discourse-saved-searches/blob/master/app/jobs/regular/saved_search_notification.rb#L36) sends automated PMs from a plugin, so that’s probably a good place to start.

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [9월 20, 2017, 8:23오전 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364/3 "2017-09-20T08:23:01Z")

</div>

> [@david](#):
>
> You can easily write errors to the logs visible at \<your forum\>/logs

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.

 ![59](https://global.discourse-cdn.com/meta/original/3X/b/e/be821eeca954ca4e81ff3df3680ec6b6d2d5d5f9.png)

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

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [9월 20, 2017, 8:42오전 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364/4 "2017-09-20T08:42:21Z")

</div>

To write to the logs, you should be able to do this from anywhere in ruby:

```plaintext
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.

---

<div class="post-metadata">

### Author: ![Bas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bas/32/294929_2.png) [@Bas](https://meta.discourse.org/u/Bas)
#### Post date: [9월 20, 2017, 8:43오전 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364/5 "2017-09-20T08:43:07Z")

</div>

> [@david](#):
>
> I think they give admin users a warning on the site itself

I’m a forum junkie, so that’s fine 🙂

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [9월 20, 2017, 6:04오후 UTC](https://meta.discourse.org/t/how-to-alert-admins-if-there-is-an-error-in-a-custom-plugin/70364/6 "2017-09-20T18:04:14Z")

</div>

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  
 ![image](https://global.discourse-cdn.com/meta/original/3X/3/5/3591ca931110f4654d5263154fa2cdd1bb598cb1.png)
