What is the best way to write to a log file when any exception occurs within the Django app without hardcoding to each function in the view i.e. middleware?
E.g. when DatabaseError,ValueError,Integrity error are raised in the views.
I need something that can be used both in production and development with DRY concept.
import logging
logger = logging.getLogger(__name__)
def my_view(request, arg1, arg):
...
if bad_mojo:
# Log an error message
logger.error('Something went wrong!')