In my Django application, I have a forms.py file in which I define loads of classes corresponding to form input screens. Each of these classes does some validation either in that attribute/field specific _clean() functions or in the overall clean() function for the form class. If validation fails in any of these clean() functions, I raise an error like this:
raise forms.ValidationError('Invalid value dude!!')When such an error is raised, the application catches the error and displays it on the form for the user.
I also have a logger defined at the top of this file like this:
import logginglogger = logging.getLogger(__name__)Now, in addition to reporting to the user the ValidationErrors, I would like to catch them and log them as errors. Is there some generic and elegant way I can get the logger to log all such errors without changing any other behavior that affects the application's user?
ليست هناك تعليقات:
إرسال تعليق