librelist archives

« back to archive

Logging form data for unexpected exceptions

Logging form data for unexpected exceptions

From:
Laszlo Papp
Date:
2013-10-11 @ 17:47
Hi all,

what is the best way of doing that while keeping my error handler operation
around? You can see snippets of the code I have, below.

Currently, I have to ask my end users to send me many form data input field
values when there is an unexpected exception in the application. This is
not yet a fully stable application, so I expect such issues every now and
then. The python trace is already saved into the log as expected, but
sometimes that is not enough, unfortunately.

What is your best practice for logging form data as well alongside the
trace? I would not like to log it all the time because that would increase
the log size unnecessarily. It would also mean more processing than
necessary.

Thank you in advance!

Cheers,
Laszlo

class FormError(Exception):
    '''
    Error when processing the form
    '''
    pass

@application.errorhandler(FormError)
def formErrorExceptionHandler(error):
    return str(error), 400

...

@application.route('/Foo', methods=['GET', 'POST'])
def foo():

    application.debug = False

    if not application.debug:
        scriptDirectoryPath = os.path.dirname(os.path.realpath(__file__))
        myHandler = logging.FileHandler(os.path.join(scriptDirectoryPath,
'foo.log'))
        myHandler.setLevel(logging.INFO)
        application.logger.addHandler(myHandler)

    if request.method == 'POST':
        ...

Re: Logging form data for unexpected exceptions

From:
Laszlo Papp
Date:
2013-10-15 @ 20:22
Ping?


On Fri, Oct 11, 2013 at 6:47 PM, Laszlo Papp <lpapp@kde.org> wrote:

> Hi all,
>
> what is the best way of doing that while keeping my error handler
> operation around? You can see snippets of the code I have, below.
>
> Currently, I have to ask my end users to send me many form data input
> field values when there is an unexpected exception in the application. This
> is not yet a fully stable application, so I expect such issues every now
> and then. The python trace is already saved into the log as expected, but
> sometimes that is not enough, unfortunately.
>
> What is your best practice for logging form data as well alongside the
> trace? I would not like to log it all the time because that would increase
> the log size unnecessarily. It would also mean more processing than
> necessary.
>
> Thank you in advance!
>
> Cheers,
> Laszlo
>
> class FormError(Exception):
>     '''
>     Error when processing the form
>     '''
>     pass
>
> @application.errorhandler(FormError)
> def formErrorExceptionHandler(error):
>     return str(error), 400
>
> ...
>
> @application.route('/Foo', methods=['GET', 'POST'])
> def foo():
>
>     application.debug = False
>
>     if not application.debug:
>         scriptDirectoryPath = os.path.dirname(os.path.realpath(__file__))
>         myHandler = logging.FileHandler(os.path.join(scriptDirectoryPath,
> 'foo.log'))
>         myHandler.setLevel(logging.INFO)
>         application.logger.addHandler(myHandler)
>
>     if request.method == 'POST':
>         ...
>
>