Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force error reporting from django management commands?

We are running custom management commands periodically on the server.

Is there any way to get something like error reporting via email working for the command?

like image 805
Oleksiy Avatar asked Jun 01 '11 20:06

Oleksiy


People also ask

What is Django admin command?

django-admin is Django's command-line utility for administrative tasks. This document outlines all it can do. In addition, manage.py is automatically created in each Django project.

What are Django exceptions and how do you handle it?

An exception is an abnormal event that leads to program failure. To deal with this situation, Django uses its own exception classes and supports all core Python exceptions as well. Django core exceptions classes are defined in django. core.

What is the use of manage py in Django?

It is your tool for executing many Django-specific tasks -- starting a new app within a project, running the development server, running your tests... It is also an extension point where you can access custom commands you write yourself that are specific to your apps.


1 Answers

You could use django logging handler AdminEmailHandler:

https://docs.djangoproject.com/en/dev/topics/logging/#django.utils.log.AdminEmailHandler

As the docs say:

This handler sends an email to the site admins for each log message it receives.

So you could use this to log an error on any exception raised in the management command, and the exception would be automatically send to the admins

like image 62
Timmy O'Mahony Avatar answered Oct 19 '22 23:10

Timmy O'Mahony