1 import logging
, time
, traceback
2 logging
.getLogger().addHandler(logging
.FileHandler("error.log"))
5 def __init__(self
, prefix
=""):
7 def write(self
, unbuffered
):
8 self
.data
+= unbuffered
10 def get_timestamp(when
=None):
13 return time
.ctime(when
) + " " + time
.tzname
[time
.daylight
]
15 def safe_call(func
, args
):
19 if isinstance(e
, SystemExit):
21 buffer = Buffer("Exception in function %s at %s:\n"
22 % (func
.__name
__, get_timestamp()))
23 traceback
.print_exc(file=buffer)
24 logging
.getLogger().error(buffer.data
)
25 # Try to report the error interactively.
26 from basic_commands
import reply
27 if len(args
) >= 2 and type(args
[0]) == type(args
[1]) == str:
29 reply(args
[0], args
[1], "Ow! Ohh, man, that didn't feel good. " \
30 +"Somebody get FunnyMan, quick!")
33 elif len(args
) and type(args
[0]) == str:
35 reply('', args
[0], "Ow! Ohh, man, that didn't feel good. " \
36 +"Somebody get FunnyMan, quick!", all
=True)
41 return lambda *args
: safe_call(func
, args
)