As Niphlod said there is a complete email script in the distro. I am not
sure it was there when I created this, but for compliance reasons I had to
strip stuff out of the request and session. Cant be emailing credit card
numbers around now ;)
I just put it in my home directory. you will need to make sure it can find
"gluon" and that you have the apropos mail libraries. It may not work for
you exactly as provided, but I pasted it more as an example that you can
manipulate the "error" files just as you could any other pickle.
In my case I just ran the script and disowned it from the parent shell PID.
HTH
On Friday, September 28, 2012 10:08:57 AM UTC-4, Hassan Alnatour wrote:
>
> Dear Dave ,
>
> Where did you add this file , and how do you use it ?
>
> Best Regards,
> Hassan Alnatour
>
> On Friday, September 28, 2012 6:38:18 AM UTC+3, Dave wrote:
>>
>> I have written a script that will load the error pickle file and email me
>> parts of it. The thing I had to be careful about was compliance. One of
>> my apps is an ecommerce app. If there is an error during the checkout
>> process, there is a chance that sensitive data may be in the error file.
>> In that case, I am stripping out the relevant tracebacks and securely
>> deleting the rest of the pickle file.
>>
>> If you do a (from gluon import *), you can essentially load the error
>> file as a pickle file and enumerate it as you choose.
>>
>> I did this all outside the web2py framework so that i wasn't creating
>> errors trying to process errors (if that makes sense)
>>
>>
>> -
>> #!/usr/bin/env python
>> from gluon import *
>> import pickle, os, time, cStringIO, smtplib
>>
>> from email.mime.multipart import MIMEMultipart
>> from email.mime.text import MIMEText
>>
>>
>> def senderror(path, errorfile):
>> infile = open(path + '/' + errorfile)
>> thiserror = pickle.load(infile)
>> infile.close()
>>
>> string_buffer = cStringIO.StringIO()
>>
>> string_buffer.write("""<html><body><h2>An error has
>> occurred.</h2><br/>\n""")
>> string_buffer.write("<h4>Exception:</h4><br/>\n")
>> string_buffer.write('%s' %
>> BEAUTIFY(thiserror['snapshot']['exception']))
>> string_buffer.write('<br/><br/>\n')
>>
>> string_buffer.write("<h4>Error Type:</h4><br/>\n")
>> string_buffer.write('%s' % BEAUTIFY(thiserror['snapshot']['etype']))
>> string_buffer.write('<br/><br/>\n')
>> string_buffer.write("<h4>Locals:</h4><br/>\n")
>> string_buffer.write('%s' % BEAUTIFY(thiserror['snapshot']['locals']))
>> string_buffer.write('<br/><br/>\n')
>>
>> string_buffer.write("<h4>Traceback:</h4><br/>\n<pre>")
>> string_buffer.write('%s' % BEAUTIFY(thiserror['traceback']))
>> string_buffer.write('</pre><br/><br/>\n')
>> string_buffer.write("<h4>Code:</h4><br/>\n<pre>")
>> string_buffer.write('%s' % BEAUTIFY(thiserror['code']))
>> string_buffer.write('</pre><br/><br/>\n')
>>
>> string_buffer.write("</body></html>\n")
>>
>> msg = MIMEMultipart('alternative')
>> text = "An error has occurred at app. Please investigate."
>> html = string_buffer.getvalue()
>>
>> msg['Subject'] = 'App ERROR: ' + errorfile
>> msg['From'] = 'FROM'
>> msg['To'] = 'TO'
>>
>> part1 = MIMEText(text, 'plain')
>> part2 = MIMEText(html, 'html')
>>
>> msg.attach(part1)
>> msg.attach(part2)
>>
>> s = smtplib.SMTP('localhost')
>> s.sendmail('FROMEMAIL', 'TOEMAIL, msg.as_string())
>> s.quit()
>>
>>
>> def main():
>> path_to_watch = "/home/app/web2py/applications/app/errors"
>> before = dict ([(f, None) for f in os.listdir (path_to_watch)])
>> while 1:
>> time.sleep (30)
>> after = dict ([(f, None) for f in os.listdir (path_to_watch)])
>> added = [f for f in after if not f in before]
>> if added: print "Errors found."
>> for error in added:
>> print 'sending email for file: ', error
>> senderror(path_to_watch, error)
>>
>> before = after
>>
>> if __name__ == "__main__":
>> main()
>>
>> On Thursday, September 27, 2012 8:32:36 AM UTC-4, Hassan Alnatour wrote:
>>>
>>> Dear ALL ,
>>>
>>> Is there a way to make all the error be sent to my email when it happens
>>> ?
>>>
>>> Best regards,
>>>
>>
--