reee
This commit is contained in:
parent
2b956f6089
commit
25c56aaeaa
@ -63,6 +63,7 @@ class RenderThread(mp.Process, pyglet.window.Window):
|
||||
self.window_config['full_screen']),
|
||||
caption=str(self.window_config['caption']),
|
||||
visible=tools.c_b(self.window_config['visible']))
|
||||
self.logger.info('setup done')
|
||||
# setup
|
||||
self.setup()
|
||||
|
||||
|
20
bin/main.py
20
bin/main.py
@ -32,15 +32,21 @@ class Game:
|
||||
self.dicts = share().dict()
|
||||
self.lists = share().list()
|
||||
# logger
|
||||
self.log_config = tools.config('configs/logging.json5')
|
||||
logging.basicConfig(filename=('logs/'+configs.name_handler(self.log_config['file']['filename']['main'], self.log_config['file']['filename']['formats'])),
|
||||
level=logging.DEBUG)
|
||||
self.root_logger_stream_hander = logging.StreamHandler()
|
||||
self.root_logger = logging.getLogger()
|
||||
logging.info('rua!')
|
||||
self.root_logger.info('aaaaa')
|
||||
logging.basicConfig(filename='logs/%s.log' % (time.time()))
|
||||
self.log_config = tools.config('configs/logging.json5', 'file')
|
||||
self.log_filename = 'logs/' + configs.name_handler(
|
||||
self.log_config['filename']['main'], self.log_config['filename']['formats'])
|
||||
self.log_file_hander = logging.FileHandler(self.log_filename)
|
||||
self.log_file_hander.setLevel(tools.log_level(self.log_config['level']))
|
||||
self.log_stream_hander = logging.StreamHandler()
|
||||
self.log_stream_hander.setLevel(tools.log_level(self.log_config['level']))
|
||||
logging.getLogger().addHandler(self.log_stream_hander)
|
||||
logging.info('logger done')
|
||||
# logging.getLogger().addHandler(self.log_file_hander)
|
||||
logging.info('logger done')
|
||||
self.server_logger = logging.getLogger()
|
||||
self.client_logger = logging.getLogger()
|
||||
self.client_logger.info('client logger and server logger done')
|
||||
# client and server
|
||||
self.client = client.RenderThread(
|
||||
self.client_logger, self.dicts, self.lists, net_mode='local')
|
||||
|
28
bin/tools.py
28
bin/tools.py
@ -3,8 +3,8 @@ writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
'''
|
||||
|
||||
import re
|
||||
import json5
|
||||
import json
|
||||
import decimal
|
||||
import logging
|
||||
from xml.dom.minidom import parse
|
||||
@ -33,6 +33,24 @@ def c_b(thing): # stand for my bool
|
||||
raise ValueError("Need a 'like bool' not anything else")
|
||||
|
||||
|
||||
def log_level(level):
|
||||
level_ = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', logging.DEBUG,
|
||||
logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]
|
||||
if level in level_:
|
||||
if (level == 'DEBUG') or (level == logging.DEBUG):
|
||||
return logging.DEBUG
|
||||
if (level == 'INFO') or (level == logging.INFO):
|
||||
return logging.INFO
|
||||
if (level == 'WARNING') or (level == logging.WARNING):
|
||||
return logging.WARNING
|
||||
if (level == 'ERROR') or (level == logging.ERROR):
|
||||
return logging.ERROR
|
||||
if (level == 'CRITICAL') or (level == logging.CRITICAL):
|
||||
return logging.CRITICAL
|
||||
else:
|
||||
raise ValueError('Need a like level thing not anything else')
|
||||
|
||||
|
||||
'''
|
||||
Physics calculation
|
||||
'''
|
||||
@ -177,13 +195,14 @@ def distance(A, B):
|
||||
|
||||
|
||||
def config(file_name, stack=None):
|
||||
type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式)
|
||||
if (type == 'json5') or (type == 'json'):
|
||||
try:
|
||||
with open(file_name, 'r', encoding='utf-8') as jf: # jf -> json file
|
||||
rd = json5.load(jf)
|
||||
except FileNotFoundError as exp:
|
||||
log = 'no config json(5) file \n file name : %s \n stack : %s' % (file_name, stack)
|
||||
log = 'no config json(5) file \n file name : %s \n stack : %s' % (
|
||||
file_name, stack)
|
||||
tools_logger.exception(log)
|
||||
raise FileNotFoundError(log)
|
||||
if stack is not None:
|
||||
@ -193,7 +212,8 @@ def config(file_name, stack=None):
|
||||
try:
|
||||
xml_load = parse(file_name)
|
||||
except FileNotFoundError as exp:
|
||||
log = 'no config json(5) file \n file name : %s \n stack : %s' % (file_name, stack)
|
||||
log = 'no config json(5) file \n file name : %s \n stack : %s' % (
|
||||
file_name, stack)
|
||||
tools_logger.exception(log)
|
||||
raise FileNotFoundError(log)
|
||||
if stack is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user