mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
logger on windows
This commit is contained in:
parent
da5b860e5f
commit
bb5024f1d7
@ -3,11 +3,22 @@
|
|||||||
#
|
#
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
if subprocess.mswindows:
|
||||||
|
import ctypes
|
||||||
|
import ctypes.wintypes
|
||||||
|
|
||||||
|
# Reference: https://gist.github.com/vsajip/758430
|
||||||
|
# https://github.com/ipython/ipython/issues/4252
|
||||||
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms686047%28v=vs.85%29.aspx
|
||||||
|
ctypes.windll.kernel32.SetConsoleTextAttribute.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD]
|
||||||
|
ctypes.windll.kernel32.SetConsoleTextAttribute.restype = ctypes.wintypes.BOOL
|
||||||
|
|
||||||
|
|
||||||
class ColorizingStreamHandler(logging.StreamHandler):
|
class ColorizingStreamHandler(logging.StreamHandler):
|
||||||
# color names to indices
|
# color names to indices
|
||||||
color_map = {
|
color_map = {
|
||||||
@ -22,17 +33,8 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# levels to (background, foreground, bold/intense)
|
# levels to (background, foreground, bold/intense)
|
||||||
if os.name == 'nt':
|
|
||||||
level_map = {
|
level_map = {
|
||||||
logging.DEBUG: (None, 'white', False),
|
logging.DEBUG: (None, 'blue', False),
|
||||||
logging.INFO: (None, 'green', False),
|
|
||||||
logging.WARNING: (None, 'yellow', False),
|
|
||||||
logging.ERROR: (None, 'red', False),
|
|
||||||
logging.CRITICAL: ('red', 'white', False)
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
level_map = {
|
|
||||||
logging.DEBUG: (None, 'white', False),
|
|
||||||
logging.INFO: (None, 'green', False),
|
logging.INFO: (None, 'green', False),
|
||||||
logging.WARNING: (None, 'yellow', False),
|
logging.WARNING: (None, 'yellow', False),
|
||||||
logging.ERROR: (None, 'red', False),
|
logging.ERROR: (None, 'red', False),
|
||||||
@ -47,7 +49,7 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
isatty = getattr(self.stream, 'isatty', None)
|
isatty = getattr(self.stream, 'isatty', None)
|
||||||
return isatty and isatty() and not self.disable_coloring
|
return isatty and isatty() and not self.disable_coloring
|
||||||
|
|
||||||
if os.name != 'nt':
|
if not subprocess.mswindows:
|
||||||
def output_colorized(self, message):
|
def output_colorized(self, message):
|
||||||
self.stream.write(message)
|
self.stream.write(message)
|
||||||
else:
|
else:
|
||||||
@ -65,8 +67,6 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def output_colorized(self, message):
|
def output_colorized(self, message):
|
||||||
import ctypes
|
|
||||||
|
|
||||||
parts = self.ansi_esc.split(message)
|
parts = self.ansi_esc.split(message)
|
||||||
write = self.stream.write
|
write = self.stream.write
|
||||||
h = None
|
h = None
|
||||||
@ -135,6 +135,7 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
message = logging.StreamHandler.format(self, record)
|
message = logging.StreamHandler.format(self, record)
|
||||||
return self.colorize(message, record)
|
return self.colorize(message, record)
|
||||||
|
|
||||||
|
|
||||||
logging.addLevelName(15, "INFO")
|
logging.addLevelName(15, "INFO")
|
||||||
logger = logging.getLogger('nhentai')
|
logger = logging.getLogger('nhentai')
|
||||||
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
|
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user