-
Notifications
You must be signed in to change notification settings - Fork 1
/
door.py
58 lines (44 loc) · 1.27 KB
/
door.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
import sys
import logging
import ctypes
import traceback
OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW
#OutputDebugString.argtypes = [ctypes.c_char_p]
class DbgViewHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
def emit(self, record):
OutputDebugString(self.format(record))
logger = logging.getLogger("pydoor")
def init_logger():
logger.setLevel(logging.DEBUG)
ch = DbgViewHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime) -25s [%(thread) 5s] %(levelname) -8s %(name) -25s %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
class InfoStreamToLogger(object):
def write(self, data):
logger.info(data)
def flush(self):
pass
class ErrorStreamToLogger(object):
def write(self, data):
logger.error(data)
def flush(self):
pass
sys.stdout = sys.__stdout__ = InfoStreamToLogger()
sys.stderr = sys.__stderr__ = ErrorStreamToLogger()
def main():
init_logger()
try:
logger.info("door.py started, embed_kernel...")
import IPython
IPython.embed_kernel()
logger.info("door.py end.")
except Exception as e:
err = traceback.format_exc()
logger.error("Exception!\n" + err)
if __name__ == "__main__":
main()