| 48 | | import warnings, logging |
| 49 | | |
| 50 | | # Needs to have the file rights to create/write into this file! |
| 51 | | LOGFILE = "PyLucid_warnings.log" |
| 52 | | |
| 53 | | try: |
| 54 | | logging.basicConfig( |
| 55 | | level=logging.DEBUG, |
| 56 | | format='%(asctime)s %(levelname)s %(message)s', |
| 57 | | filename=LOGFILE, |
| 58 | | filemode='a' |
| 59 | | ) |
| 60 | | except IOError, err: |
| 61 | | raise IOError("Can't setup low level warning redirect: %s" % err) |
| 62 | | |
| 63 | | log = logging.debug |
| 64 | | log("PyLucid warnings logging started.") |
| 65 | | |
| 66 | | warning_container = [] |
| 67 | | |
| 68 | | def showwarning(message, category, filename, lineno): |
| 69 | | |
| 70 | | msg = unicode(message) |
| 71 | | filename = u"..." + filename[-30:] |
| 72 | | msg += u" (%s - line %s)" % (filename, lineno) |
| 73 | | |
| 74 | | log(msg) |
| 75 | | |
| 76 | | old_showwarning = warnings.showwarning |
| 77 | | warnings.showwarning = showwarning |
| | 48 | #import warnings, logging |
| | 49 | # |
| | 50 | ## Needs to have the file rights to create/write into this file! |
| | 51 | #LOGFILE = "PyLucid_warnings.log" |
| | 52 | # |
| | 53 | #try: |
| | 54 | # logging.basicConfig( |
| | 55 | # level=logging.DEBUG, |
| | 56 | # format='%(asctime)s %(levelname)s %(message)s', |
| | 57 | # filename=LOGFILE, |
| | 58 | # filemode='a' |
| | 59 | # ) |
| | 60 | #except IOError, err: |
| | 61 | # raise IOError("Can't setup low level warning redirect: %s" % err) |
| | 62 | # |
| | 63 | #log = logging.debug |
| | 64 | #log("PyLucid warnings logging started.") |
| | 65 | # |
| | 66 | #warning_container = [] |
| | 67 | # |
| | 68 | #def showwarning(message, category, filename, lineno): |
| | 69 | # |
| | 70 | # msg = unicode(message) |
| | 71 | # filename = u"..." + filename[-30:] |
| | 72 | # msg += u" (%s - line %s)" % (filename, lineno) |
| | 73 | # |
| | 74 | # log(msg) |
| | 75 | # |
| | 76 | #old_showwarning = warnings.showwarning |
| | 77 | #warnings.showwarning = showwarning |