0

I have a python app in the GAE Standard Environment and I log errors using the builtin python logging api:

logging.error('some error')

This error then appears in StackDriver Logging correctly as an error log item.

Is there a setting somewhere which I could set so I get an email notification when a new error log item is added to StackDriver Logging?

Note that I don't mean the StackDriver Error Reporting page. That is something else, the above error does not appear there, because for StackDriver Error Reporting items AFAIK I need to use some specific API call.

I mean the StackDriver Logging viewer where standard python logs appear. Can I set a notification there, so I get an email when StackDriver Logging receives an error log item from my python app?

Tom
  • 7,515
  • 7
  • 38
  • 54
  • FWIW, I was pleasantly surprised to get email notifications from Google about new errors encountered in my apps (that have been running for a while). I don't recall doing anything specific for that. – Dan Cornilescu May 11 '19 at 20:19
  • Are these errors logged by you in the app? Do these errors also show up in StackDriver Error Reporting? (https://console.cloud.google.com/errors) Because if so then you probably do something else than builtin python logging. – Tom May 11 '19 at 20:26
  • Ah, I missed that point. No, these were unintended tracebacks causing server-side 500 errors. Never mind. – Dan Cornilescu May 11 '19 at 22:59

2 Answers2

1

I found the solution, logging.error does not appear in StackDriver Error Reporting, but logging.exception does.

So the solution is raising an exception in your code and then catching it and using logging.exception. In this case the error goes to StackDriver Error Reporting and you get a notification (because the log item has a stack trace, so it knows it's an error).

Alternatively, you don't have to catch your own exception,you can let it fly, you get a notification in that case also, but then the server returns 500, so by catching it you can exit more gracefully.

Tom
  • 7,515
  • 7
  • 38
  • 54
0

You can use Error Reporting Subscribing to notifications from google cloud console

or

Using [AppEngine LogService][2], you can fetch all error logs from appengine/stackdriver, and you need to set cron job to fetch error logs and send email with that errors.

https://stackoverflow.com/a/21655135/8055450

Dharmesh Fumakiya
  • 2,276
  • 2
  • 11
  • 17