def initialize_debug_mode(self, mode, logdir = None):
# on windows systems all output to stdout goes to a black hole
# if py2exe is used.
# so we use a normal window and redirect output from sys.stderr
# and sys.stdout. it is easier to use for windows users.
#
# but we have to do a second trick to get the output from the logging
# module WITHOUT (!) writing the output twice, one in the window, one
# to stderr/console/py2exe:
# removing the handlers from the root logger and reinitialized via
# logging.basicConfig
# there is no other way to prevent py2exe showing a error message and
# generating the .log file in the installation directory
try:
if os.name == 'nt' or os.name.startswith('win'): # win32, win64
if mode:
if self.debugWindow is None:
self.debugWindow = DebugWindow(None)
if not self.windowredirector:
self.windowredirector = DebugWindowRedirector(self.debugWindow, logdir)
else:
self.windowredirector.set_logdir(logdir)
sys.stderr = sys.stdout = self.windowredirector
# resetting default logging configuration
logging.getLogger().handlers = []
logging.basicConfig(stream = sys.stderr, format='%(asctime)s: %(levelname)s: %(name)s(%(module)s:%(lineno)d): %(message)s', datefmt='%Y-%m-%dT%H:%M:%S')
elif hasattr(sys, 'frozen') and sys.frozen == 'windows_exe':
# if a windows exe is build via py2exe, redirect all output
if not self.blackholebuffer:
self.blackholebuffer = DebugBlackholeBufferRedirector(sys.stderr, logdir)
else:
self.blackholebuffer.set_logdir(logdir)
sys.stderr = sys.stdout = self.blackholebuffer
# resetting default logging configuration
logging.getLogger().handlers = []
logging.basicConfig(stream = sys.stderr, format='%(asctime)s: %(levelname)s: %(name)s(%(module)s:%(lineno)d): %(message)s', datefmt='%Y-%m-%dT%H:%M:%S')
except:
log.exception('')
#
# used on windows systems
# shows a windows with a text view which displays the
# debug output provided by DebugWindowRedirector
#
评论列表
文章目录