From bb868482186f05f70e92dd17e57c80e98bd7d09f Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 28 八月 2023 14:55:35 +0800 Subject: [PATCH] 系统日志记录 --- huaxin_client/l2_client.py | 2 log_module/log_export.py | 16 ++++++++ huaxin_client/l1_subscript_codes_manager.py | 8 ++-- huaxin_client/trade_client.py | 2 db/redis_manager_delegate.py | 3 + trade/huaxin/trade_server.py | 22 +++++++++- main.py | 5 +- outside_api_command_manager.py | 3 + huaxin_client/l1_client.py | 5 ++ trade/huaxin/trade_api_server.py | 5 ++ trade/huaxin/huaxin_trade_data_update.py | 3 + 11 files changed, 59 insertions(+), 15 deletions(-) diff --git a/db/redis_manager_delegate.py b/db/redis_manager_delegate.py index 32d382e..a461259 100644 --- a/db/redis_manager_delegate.py +++ b/db/redis_manager_delegate.py @@ -8,7 +8,7 @@ import redis import constant -from log_module.log import logger_redis_debug +from log_module.log import logger_redis_debug, logger_system from utils import tool, middle_api_protocol config = constant.REDIS_CONFIG @@ -172,6 +172,7 @@ # 杩愯寮傛浠诲姟 @classmethod def run_loop(cls): + logger_system.info("鍚姩Redis鏁版嵁鍚屾鏈嶅姟") while True: try: data = cls.__async_task_queue.get() diff --git a/huaxin_client/l1_client.py b/huaxin_client/l1_client.py index 8b43b5e..17351c2 100644 --- a/huaxin_client/l1_client.py +++ b/huaxin_client/l1_client.py @@ -146,12 +146,13 @@ for i in range(15): try: codes_sh, codes_sz = l1_subscript_codes_manager.get_codes() + logger_local_huaxin_l1.info(f"鑾峰彇涓婅瘉锛屾繁璇佷唬鐮佹暟閲忥細sh-{len(codes_sh)} sz-{len(codes_sz)}") break except Exception as e: logger_local_huaxin_l1.exception(e) time.sleep(4) - + logger_system.info(f"鑾峰彇L1璁㈤槄鐩爣绁ㄦ暟閲忥細sh-{len(codes_sh)} sz-{len(codes_sz)}") # 鎵撳嵃鎺ュ彛鐗堟湰鍙� print(xmdapi.CTORATstpXMdApi_GetApiVersion()) @@ -176,6 +177,8 @@ # 鍚姩鎺ュ彛 api.Init() + logger_system.info("L1璁㈤槄鏈嶅姟鍚姩鎴愬姛") + # 绛夊緟绋嬪簭缁撴潫 while True: print("鏁伴噺", len(level1_data_dict)) diff --git a/huaxin_client/l1_subscript_codes_manager.py b/huaxin_client/l1_subscript_codes_manager.py index 50b7656..54c1f02 100644 --- a/huaxin_client/l1_subscript_codes_manager.py +++ b/huaxin_client/l1_subscript_codes_manager.py @@ -88,10 +88,10 @@ def get_codes(): - # codes_sh, codes_sz = get_codes_from_file() - # if not codes_sh or not codes_sz: - return request_l1_subscript_target_codes() - # return codes_sh, codes_sz + codes_sh, codes_sz = get_codes_from_file() + if not codes_sh or not codes_sz: + return request_l1_subscript_target_codes() + return codes_sh, codes_sz if __name__ == '__main__': diff --git a/huaxin_client/l2_client.py b/huaxin_client/l2_client.py index 277d4ae..6a6ec95 100644 --- a/huaxin_client/l2_client.py +++ b/huaxin_client/l2_client.py @@ -577,7 +577,7 @@ global l2CommandManager l2CommandManager = command_manager.L2CommandManager() l2CommandManager.init(MyL2ActionCallback()) - print("l2_client鍚姩鎴愬姛") + logger_system.info("l2_client鍚姩鎴愬姛") while True: time.sleep(2) diff --git a/huaxin_client/trade_client.py b/huaxin_client/trade_client.py index 9f24068..9d546fa 100644 --- a/huaxin_client/trade_client.py +++ b/huaxin_client/trade_client.py @@ -1034,7 +1034,7 @@ tradeCommandManager = command_manager.TradeCommandManager() tradeCommandManager.init(MyTradeActionCallback(), l2pipe, pipe_strategy) tradeCommandManager.run() - print("trade_client鍚姩鎴愬姛") + logger_system.info("trade_client鍚姩鎴愬姛") while True: time.sleep(2) diff --git a/log_module/log_export.py b/log_module/log_export.py index 03ffdcf..d1bf92d 100644 --- a/log_module/log_export.py +++ b/log_module/log_export.py @@ -323,6 +323,22 @@ return fdatas +# 璇诲彇绯荤粺鏃ュ織 +def load_system_log(): + path = f"{constant.get_path_prefix()}/logs/gp/system/system.{tool.get_now_date_str()}.log" + fdatas = [] + if os.path.exists(path): + with open(path, 'r', encoding="utf-8") as f: + lines = f.readlines() + for line in lines: + if line: + time_str = line.split("|")[0].strip() + level = line.split("|")[1].strip() + data = line.split("|")[2].split(" - ")[1].strip() + fdatas.append((time_str, level, data)) + return fdatas + + if __name__ == '__main__': load_huaxin_local_buy_no() # print(get_h_cancel_compute_info("603912")) diff --git a/main.py b/main.py index de7f20a..c7fc6d7 100644 --- a/main.py +++ b/main.py @@ -47,7 +47,7 @@ # 涓绘湇鍔� def createServer(pipe): - print("create Server") + logger_system.info("create Server") laddr = "", 9001 tcpserver = MyThreadingTCPServer(laddr, MyBaseRequestHandle, pipe_trade=pipe) # 娉ㄦ剰锛氬弬鏁版槸MyBaseRequestHandle try: @@ -58,7 +58,7 @@ def createDataServer(): - print("create DataServer") + logger_system.info("create DataServer") tcpserver = data_server.run("", 9004) tcpserver.serve_forever() try: @@ -70,6 +70,7 @@ if __name__ == '__main__': logger_l2_trade.info("鍚姩绋嬪簭") + logger_system.info("鍚姩绋嬪簭") log.close_print() # 绛栫暐涓巗erver闂寸殑閫氫俊 pss_server, pss_strategy = multiprocessing.Pipe() diff --git a/outside_api_command_manager.py b/outside_api_command_manager.py index 193de05..9e7b63b 100644 --- a/outside_api_command_manager.py +++ b/outside_api_command_manager.py @@ -52,6 +52,7 @@ API_TYPE_CODE_TRADE_STATE = "code_trade_state" # 浠g爜浜ゆ槗鐘舵�� API_TYPE_GET_ENV = "get_env" # 鑾峰彇鐜淇℃伅 API_TYPE_SYNC_L1_TARGET_CODES = "sync_l1_subscript_codes" # 鍚屾L1闇�瑕佽闃呯殑浠g爜 +API_TYPE_SYSTEM_LOG = "system_log" # 绯荤粺鏃ュ織 class ActionCallback(object): @@ -187,6 +188,8 @@ cls.action_callback.OnGetEnvInfo(client_id, request_id, data) elif content_type == API_TYPE_SYNC_L1_TARGET_CODES: cls.action_callback.OnSyncL2SubscriptCodes(client_id, request_id) + elif content_type == API_TYPE_SYSTEM_LOG: + cls.action_callback.OnSystemLog(client_id, request_id, data) except Exception as e: logging.exception(e) pass diff --git a/trade/huaxin/huaxin_trade_data_update.py b/trade/huaxin/huaxin_trade_data_update.py index 74342a7..d359ac1 100644 --- a/trade/huaxin/huaxin_trade_data_update.py +++ b/trade/huaxin/huaxin_trade_data_update.py @@ -6,7 +6,7 @@ import threading import time -from log_module.log import hx_logger_trade_debug +from log_module.log import hx_logger_trade_debug, logger_system from trade import trade_huaxin, trade_manager from trade.huaxin import huaxin_trade_api, huaxin_trade_record_manager from trade.huaxin.huaxin_trade_record_manager import TradeOrderIdManager @@ -16,6 +16,7 @@ def __read_trade_data_queue(): + logger_system.info("鍚姩璇诲彇浜ゆ槗鏁版嵁鏇存柊闃熷垪") while True: try: data = trade_data_request_queue.get() diff --git a/trade/huaxin/trade_api_server.py b/trade/huaxin/trade_api_server.py index 192226d..65009d8 100644 --- a/trade/huaxin/trade_api_server.py +++ b/trade/huaxin/trade_api_server.py @@ -14,6 +14,7 @@ from db.redis_manager_delegate import RedisUtils from l2 import l2_data_manager_new from l2.huaxin import huaxin_target_codes_manager +from log_module.log import logger_system from third_data import block_info from third_data.history_k_data_util import HistoryKDatasUtils, JueJinApi from third_data.kpl_data_manager import KPLDataManager @@ -420,6 +421,7 @@ def __set_target_codes(pipe_l2): + logger_system.info("鍚姩璇诲彇L2璁㈤槄浠g爜闃熷垪") while True: try: _datas = huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.pop() @@ -446,6 +448,7 @@ def __read_sync_task(pipe): + logger_system.info("鍚姩璇诲彇鏁版嵁鍚屾鏈嶅姟") while True: try: if pipe: @@ -491,7 +494,7 @@ def run(pipe_server, pipe_l2): - print("create TradeApiServer") + logger_system.info("create TradeApiServer") # 鎷夊彇浜ゆ槗淇℃伅 huaxin_trade_data_update.run() # diff --git a/trade/huaxin/trade_server.py b/trade/huaxin/trade_server.py index 73ba13b..5e275a3 100644 --- a/trade/huaxin/trade_server.py +++ b/trade/huaxin/trade_server.py @@ -29,7 +29,7 @@ from l2.huaxin import huaxin_target_codes_manager from l2.huaxin.huaxin_target_codes_manager import HuaXinL1TargetCodesManager from l2.l2_data_manager_new import L2TradeDataProcessor -from log_module import async_log_util +from log_module import async_log_util, log_export from log_module.log import hx_logger_l2_upload, hx_logger_contact_debug, hx_logger_trade_callback, \ hx_logger_l2_orderdetail, hx_logger_l2_transaction, hx_logger_l2_market_data, logger_l2_trade_buy_queue, \ logger_l2_g_cancel, logger_debug, logger_system @@ -362,7 +362,8 @@ is_normal = l2_data_util.load_l2_data(code, load_latest=False) volume_rate = code_volumn_manager.get_volume_rate(code) volume_rate_index = code_volumn_manager.get_volume_rate_index(volume_rate) - m_val = L2PlaceOrderParamsManager(code, True, volume_rate, volume_rate_index, None).get_m_val()[0] + m_val = \ + L2PlaceOrderParamsManager(code, True, volume_rate, volume_rate_index, None).get_m_val()[0] limit_up_price = gpcode_manager.get_limit_up_price(code) m_val_num = int(m_val / (float(limit_up_price) * 100)) @@ -734,6 +735,21 @@ except Exception as e: logger_debug.error(e) + def OnSystemLog(self, client_id, request_id, data): + logger_debug.debug("OnSystemLog") + try: + start_index = data["start_index"] + count = data["count"] + # 璇诲彇绯荤粺鏃ュ織 + logs_data = log_export.load_system_log() + total_count = len(logs_data) + if start_index > 0: + logs_data = logs_data[start_index:start_index+count] + result = {"code": 0, "data": {"total_count": total_count, "list": logs_data}} + self.send_response(result, client_id, request_id) + except Exception as e: + logger_debug.error(e) + def run(pipe_trade, pipe_l1): # 鎵ц涓�浜涘垵濮嬪寲鏁版嵁 @@ -757,7 +773,7 @@ t1 = threading.Thread(target=lambda: async_log_util.run_sync(), daemon=True) t1.start() - print("create TradeServer") + logger_system.info("create TradeServer") t1 = threading.Thread(target=lambda: clear_invalid_client(), daemon=True) t1.start() -- Gitblit v1.8.0