ruuuuuuuuuuuuuuuuuuaaaa!

logggggggggggggggggggging!
This commit is contained in:
沈瑗杰 2021-02-14 22:15:05 +08:00
parent 39d505cdf4
commit 2b956f6089
6 changed files with 54 additions and 47 deletions

View File

@ -3,8 +3,7 @@ writen by shenjackyuanjie
mail: 3695888@qq.com mail: 3695888@qq.com
''' '''
import os
import bin
import sys import sys
from bin import main from bin import main

View File

@ -32,7 +32,6 @@ class RenderThread(mp.Process, pyglet.window.Window):
:param net_mode: 网络模式 # local / ip :param net_mode: 网络模式 # local / ip
''' '''
# do father class __init__() # do father class __init__()
Window.__init__(self)
mp.Process.__init__(self) mp.Process.__init__(self)
# logging # logging
self.logger = logger self.logger = logger
@ -52,7 +51,7 @@ class RenderThread(mp.Process, pyglet.window.Window):
self.window_config = tools.config('sys_value/window.json5') self.window_config = tools.config('sys_value/window.json5')
# dic # dic
self.ships = {} # all ship(part) self.ships = {} # all ship(part)
self.planet_system = tools.configs('sys_vlaue/planet.json5') # hole planet system self.planet_system = tools.config('sys_value/planet.json5') # hole planet system
# list # list
# re stuff # re stuff
self.ipv4_re = re.compile( self.ipv4_re = re.compile(
@ -82,18 +81,17 @@ class RenderThread(mp.Process, pyglet.window.Window):
self.textures = {} self.textures = {}
# parts # parts
self.textures['part'] = {} self.textures['part'] = {}
parts = tools.configs('sys_value/parts.json5') parts = tools.config('sys_value/parts.json5')
for part in parts: for part in parts:
name = parts[part] path = parts[part][2][0]
path = part[2][0] path = 'textures/' + path
part_image = image.load(path) part_image = image.load(path)
self.textures['part'][name] = part_image self.textures['part'][part] = part_image
'''
draws # draws
'''
def on_draw(self): def on_draw(self):
self.logger.info('testing!') print('rua!')
def build_draw(self): def build_draw(self):
pass pass

View File

@ -32,37 +32,15 @@ class Game:
self.dicts = share().dict() self.dicts = share().dict()
self.lists = share().list() self.lists = share().list()
# logger # logger
# log config
self.log_config = tools.config('configs/logging.json5') self.log_config = tools.config('configs/logging.json5')
self.log_file_config = self.log_config['file'] logging.basicConfig(filename=('logs/'+configs.name_handler(self.log_config['file']['filename']['main'], self.log_config['file']['filename']['formats'])),
self.log_file_handler = logging.FileHandler('logs/%s' % (configs.name_handler( level=logging.DEBUG)
self.log_file_config['filename']['main'], self.log_file_config['filename']['formats']))) self.root_logger_stream_hander = logging.StreamHandler()
# logger self.root_logger = logging.getLogger()
# all logger logging.info('rua!')
# client logger self.root_logger.info('aaaaa')
self.client_log_config = self.log_config['client'] self.server_logger = logging.getLogger()
self.client_logger = logging.getLogger('client') self.client_logger = logging.getLogger()
self.client_fmt = logging.Formatter(
fmt=self.client_log_config['fmt'],
datefmt=self.client_log_config['date_fmt'])
self.client_stream_handler = logging.StreamHandler()
self.client_stream_handler.setLevel(self.client_log_config['level'])
self.client_stream_handler.setFormatter(self.client_fmt)
self.client_logger.addHandler(self.client_stream_handler)
# server logger
self.server_log_config = self.log_config['server']
self.server_logger = logging.getLogger('server')
self.server_fmt = logging.Formatter(
fmt=self.server_log_config['fmt'],
datefmt=self.server_log_config['date_fmt'])
self.server_stream_handler = logging.StreamHandler()
self.server_stream_handler.setLevel(self.server_log_config['level'])
self.server_stream_handler.setFormatter(self.server_fmt)
self.server_logger.addHandler(self.server_stream_handler)
# file logger
self.log_formatter = logging.Formatter(
fmt=self.log_file_config['fmt'],
datefmt=self.log_file_config['date_fmt'])
# client and server # client and server
self.client = client.RenderThread( self.client = client.RenderThread(
self.client_logger, self.dicts, self.lists, net_mode='local') self.client_logger, self.dicts, self.lists, net_mode='local')

View File

@ -23,14 +23,14 @@ some tools
def c_b(thing): # stand for my bool def c_b(thing): # stand for my bool
yes = ['True', 'TRUE', '1', 1] yes = ['True', 'TRUE', 'true', '1', 1, True]
no = ['False', 'FALSE', '0', 0] no = ['False', 'FALSE', 'false', '0', 0, False]
if thing in yes: if thing in yes:
return True return True
elif thing in no: elif thing in no:
return False return False
else: else:
raise ValueError('Need a 'like bool' not anything else') raise ValueError("Need a 'like bool' not anything else")
''' '''
@ -180,7 +180,7 @@ 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'): if (type == 'json5') or (type == 'json'):
try: try:
with open(file_name, 'r') as jf: # jf -> json file with open(file_name, 'r', encoding='utf-8') as jf: # jf -> json file
rd = json5.load(jf) rd = json5.load(jf)
except FileNotFoundError as exp: 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)

View File

@ -3,6 +3,6 @@ import json5
import pprint import pprint
with open('configs/view.json5') as view: with open('sys_value/parts.json5', 'r+', encoding='utf-8') as view:
a = view.read() a = view.read()
pprint.pprint(a) pprint.pprint(a)

32
tests/test_logging.py Normal file
View File

@ -0,0 +1,32 @@
import logging
# set up logging to file - see previous section for more details
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='test.log',
filemode='w')
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
# Now, we can log to the root logger, or any other logger. First the root...
logging.info('Jackdaws love my big sphinx of quartz.')
# Now, define a couple of other loggers which might represent areas in your
# application:
logger1 = logging.getLogger('myapp.area1')
logger2 = logging.getLogger('myapp.area2')
logger1.debug('Quick zephyrs blow, vexing daft Jim.')
logger1.info('How quickly daft jumping zebras vex.')
logger2.warning('Jail zesty vixen who grabbed pay from quack.')
logger2.error('The five boxing wizards jump quickly.')