crash update
This commit is contained in:
parent
41a113bd6b
commit
56d291bcb1
@ -11,6 +11,8 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from libs.MCDR.version import Version
|
||||
|
||||
game_version = Version("0.6.2")
|
||||
@ -18,16 +20,25 @@ __version__ = game_version
|
||||
|
||||
DR_options = {
|
||||
'InputBox_use_TextEntry': False,
|
||||
'playing': False
|
||||
'playing': False,
|
||||
'debugging': False
|
||||
}
|
||||
|
||||
_DR_options_type = {
|
||||
'InputBox_use_TextEntry': bool,
|
||||
'playing': bool
|
||||
'playing': bool,
|
||||
'debugging': bool
|
||||
}
|
||||
|
||||
|
||||
def DR_option_type(config_name: str):
|
||||
if config_name in _DR_options_type:
|
||||
return _DR_options_type[config_name]
|
||||
return Any
|
||||
|
||||
|
||||
if DR_options['playing']:
|
||||
from .api import new_thread
|
||||
from .utils import new_thread
|
||||
|
||||
|
||||
def think_it(something):
|
||||
|
@ -26,22 +26,24 @@ from typing import Optional
|
||||
# this can't be crash , or the game will really crash!
|
||||
|
||||
# TODO 写完它
|
||||
import Difficult_Rocket
|
||||
|
||||
Head_message = """# ----- Difficult Rocket Crash Report -----
|
||||
## Time: {now_time}
|
||||
## Traceback
|
||||
"""
|
||||
|
||||
Process_message = """## Process info
|
||||
"""
|
||||
Run_message = """## Difficult Rocket running status\n"""
|
||||
|
||||
Thread_message = """## Thread info
|
||||
"""
|
||||
DR_configs = """### game config"""
|
||||
|
||||
Python_message = """## Python info
|
||||
"""
|
||||
Process_message = """## Process info\n"""
|
||||
|
||||
System_message = """## System info
|
||||
"""
|
||||
Thread_message = """## Thread info\n"""
|
||||
|
||||
Python_message = """## Python info\n"""
|
||||
|
||||
System_message = """## System info\n"""
|
||||
|
||||
all_thread = [threading.main_thread()]
|
||||
all_process = [multiprocessing.current_process()]
|
||||
@ -50,7 +52,7 @@ record_thread = True
|
||||
|
||||
def crash_info_handler(info: str = None) -> str:
|
||||
if not info:
|
||||
info = traceback.format_exc()
|
||||
info = traceback.format_exc().replace('<', '< ')
|
||||
format_info = f"<pre>\n{info}</pre>\n"
|
||||
return format_info
|
||||
|
||||
@ -63,6 +65,10 @@ def markdown_line_handler(string: Optional[str or bool or int or float], code: b
|
||||
return '{}{}{}'.format(lvl, f_string, end)
|
||||
|
||||
|
||||
def to_code(string: str):
|
||||
return '`' + string + '`'
|
||||
|
||||
|
||||
def create_crash_report(info: str = None) -> None:
|
||||
crash_info = crash_info_handler(info)
|
||||
if 'crash_report' not in os.listdir('./'):
|
||||
@ -71,9 +77,23 @@ def create_crash_report(info: str = None) -> None:
|
||||
filename = 'crash-{}.md'.format(date_time)
|
||||
with open('./crash_report/{}'.format(filename), 'w+', encoding='utf-8') as crash_file:
|
||||
# 开头信息
|
||||
crash_file.write(Head_message)
|
||||
crash_file.write(Head_message.format(now_time=time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(time.time()))))
|
||||
# 崩溃信息
|
||||
crash_file.write(crash_info)
|
||||
# 运行状态信息
|
||||
crash_file.write(Run_message)
|
||||
crash_file.write(markdown_line_handler(f'DR Version: {Difficult_Rocket.game_version}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'Running Dir: {os.path.abspath(os.curdir)}', level=1))
|
||||
crash_file.write(markdown_line_handler(f': {os.name=}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'DR Version: {str(Difficult_Rocket.Version)}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'DR Version: {str(Difficult_Rocket.Version)}', level=1))
|
||||
# # DR 的游戏设置
|
||||
crash_file.write(DR_configs)
|
||||
try:
|
||||
for key, value in Difficult_Rocket.DR_options.items():
|
||||
crash_file.write(markdown_line_handler(f'Option: {to_code(key)} Type: {to_code(Difficult_Rocket)}', level=1))
|
||||
except RuntimeError:
|
||||
pass
|
||||
# 多进程信息
|
||||
crash_file.write(Process_message)
|
||||
for process in all_process:
|
||||
@ -92,24 +112,24 @@ def create_crash_report(info: str = None) -> None:
|
||||
crash_file.write(markdown_line_handler(f'Running: {thread.is_alive()}', level=2))
|
||||
# Python 信息
|
||||
crash_file.write(Python_message)
|
||||
crash_file.write(markdown_line_handler(f'Version: {platform.python_version()}', code=True, level=1))
|
||||
# crash_file.write(markdown_line_handler(f'Version tuple: {platform.python_version_tuple()}', code=True, level=1))
|
||||
# crash_file.write(markdown_line_handler(f'Build: {platform.python_build()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'Implementation: {platform.python_implementation()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'Compiler: {platform.python_compiler()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'Version: {to_code(platform.python_version())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'Branch: {to_code(platform.python_branch())}', level=1))
|
||||
# crash_file.write(markdown_line_handler(f'Build: {platform.python_implementation()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'Implementation: {to_code(platform.python_implementation())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'Compiler: {to_code(platform.python_compiler())}', level=1))
|
||||
# 电脑系统信息
|
||||
crash_file.write(System_message)
|
||||
crash_file.write(markdown_line_handler(f'System: {platform.platform()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'Computer name: {platform.node()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'machine: {platform.machine()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'processor: {platform.processor()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'release: {platform.release()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'version: {platform.version()}', code=True, level=1))
|
||||
crash_file.write(markdown_line_handler(f'System: {to_code(platform.platform())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'Computer name: {to_code(platform.node())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'machine: {to_code(platform.machine())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'processor: {to_code(platform.processor())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'release: {to_code(platform.release())}', level=1))
|
||||
crash_file.write(markdown_line_handler(f'version: {to_code(platform.version())}', level=1))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.chdir('../')
|
||||
os.chdir('../../')
|
||||
try:
|
||||
raise FileNotFoundError('abc')
|
||||
except:
|
||||
except FileNotFoundError:
|
||||
create_crash_report()
|
||||
|
@ -75,5 +75,5 @@ color_print(31)
|
||||
print('some error', reset_color)
|
||||
|
||||
print('fatal: ', end='')
|
||||
color_print(37, 41)
|
||||
color_print(33, 41)
|
||||
print('some fatal', reset_color)
|
||||
|
@ -6,7 +6,7 @@ import atexit
|
||||
import threading
|
||||
|
||||
from time import strftime
|
||||
from typing import Optional, Union, Dict, Iterable, Tuple, List
|
||||
from typing import Optional, Union, Dict, Iterable, Tuple, List, Callable
|
||||
from logging import NOTSET, DEBUG, INFO, WARNING, ERROR, FATAL
|
||||
|
||||
from Difficult_Rocket.utils.thread import ThreadLock
|
||||
@ -40,6 +40,7 @@ NOTSET = 0
|
||||
"""
|
||||
ALL = NOTSET
|
||||
TRACE = 5
|
||||
FINE = 7
|
||||
|
||||
|
||||
class LogFileCache:
|
||||
@ -140,7 +141,6 @@ class Logger:
|
||||
|
||||
self.file_cache = LogFileCache()
|
||||
self.warn = self.warning
|
||||
self.fine = self.detail
|
||||
|
||||
def make_log(self, *values: object,
|
||||
level: int,
|
||||
@ -150,50 +150,56 @@ class Logger:
|
||||
if level < self.level:
|
||||
return None
|
||||
print(level, values, sep, end, flush, sep='|')
|
||||
write_text = sep.join(values)
|
||||
print(write_text)
|
||||
write_text = sep.join(i if type(i) is str else str(i) for i in values).__add__(end)
|
||||
print(write_text, end='')
|
||||
...
|
||||
|
||||
def detail(self, *values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
self.make_log(*values, level=DETAIL, sep=sep, end=end, flush=flush)
|
||||
def trace(self, *values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
return self.make_log(*values, level=TRACE, sep=sep, end=end, flush=flush)
|
||||
|
||||
def fine(self, *values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
return self.make_log(*values, level=FINE, sep=sep, end=end, flush=flush)
|
||||
|
||||
def debug(self,
|
||||
*values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
self.make_log(*values, level=DEBUG, sep=sep, end=end, flush=flush)
|
||||
return self.make_log(*values, level=DEBUG, sep=sep, end=end, flush=flush)
|
||||
|
||||
def info(self,
|
||||
*values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
self.make_log(*values, level=INFO, sep=sep, end=end, flush=flush)
|
||||
return self.make_log(*values, level=INFO, sep=sep, end=end, flush=flush)
|
||||
|
||||
def warning(self,
|
||||
*values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
self.make_log(*values, level=WARNING, sep=sep, end=end, flush=flush)
|
||||
return self.make_log(*values, level=WARNING, sep=sep, end=end, flush=flush)
|
||||
|
||||
def error(self,
|
||||
*values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
self.make_log(*values, level=ERROR, sep=sep, end=end, flush=flush)
|
||||
return self.make_log(*values, level=ERROR, sep=sep, end=end, flush=flush)
|
||||
|
||||
def fatal(self,
|
||||
*values: object,
|
||||
sep: Optional[str] = ' ',
|
||||
end: Optional[str] = '\n',
|
||||
flush: Optional[bool] = False) -> None:
|
||||
self.make_log(*values, level=FATAL, sep=sep, end=end, flush=flush)
|
||||
return self.make_log(*values, level=FATAL, sep=sep, end=end, flush=flush)
|
||||
|
||||
|
||||
def color_in_033(*args) -> str:
|
||||
@ -211,7 +217,6 @@ def logging_color() -> Dict:
|
||||
return {'info': ..., 'message': ...}
|
||||
|
||||
|
||||
|
||||
logger_configs = {
|
||||
'Logger': {
|
||||
'root': {
|
||||
@ -223,12 +228,13 @@ logger_configs = {
|
||||
},
|
||||
},
|
||||
'Color': {
|
||||
TRACE: {'info': '', 'message': '\033[48;2;40;40;40m'},
|
||||
DEBUG: {'info': '', 'message': '\033[32;40m'},
|
||||
INFO: {'info': '', 'message': '\033[33;40m'},
|
||||
WARNING: {'info': '', 'message': ''},
|
||||
ERROR: {'info': '', 'message': ''},
|
||||
FATAL: {'info': '', 'message': ''}
|
||||
TRACE: {'info': '\033[34;40m', 'message': '\033[48;2;40;40;40m'},
|
||||
FINE: {'info': '', 'message': '\033[35m'},
|
||||
DEBUG: {'info': '', 'message': '\033[38;2;133;138;149m'},
|
||||
INFO: {'info': '\033[32;40m', 'message': ''},
|
||||
WARNING: {'info': '', 'message': '\033[33m'},
|
||||
ERROR: {'info': '', 'message': '\033[31m'},
|
||||
FATAL: {'info': '', 'message': '\033[33;41'}
|
||||
},
|
||||
'File': {
|
||||
'main_log_file': {
|
||||
@ -283,6 +289,6 @@ def get_logger(name: str = 'name') -> Logger:
|
||||
if __name__ == "__main__":
|
||||
# 在这里可以使用 add_kwargs_to_global
|
||||
some_logger = Logger(name='aaa')
|
||||
some_logger.level = DETAIL
|
||||
some_logger.level = ALL
|
||||
some_logger.warn('aaaa', 'aaaa')
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user