sycommon-python-lib 0.1.26__py3-none-any.whl → 0.1.38__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sycommon/logging/kafka_log.py +16 -6
- sycommon/logging/sql_logger.py +2 -8
- sycommon/models/mqlistener_config.py +1 -0
- sycommon/rabbitmq/rabbitmq_client.py +575 -254
- sycommon/rabbitmq/rabbitmq_service.py +255 -131
- sycommon/services.py +64 -22
- sycommon/synacos/example.py +153 -0
- sycommon/synacos/example2.py +129 -0
- sycommon/synacos/feign.py +70 -405
- sycommon/synacos/feign_client.py +317 -0
- sycommon/synacos/nacos_service.py +15 -10
- sycommon/synacos/param.py +75 -0
- {sycommon_python_lib-0.1.26.dist-info → sycommon_python_lib-0.1.38.dist-info}/METADATA +9 -9
- {sycommon_python_lib-0.1.26.dist-info → sycommon_python_lib-0.1.38.dist-info}/RECORD +17 -13
- {sycommon_python_lib-0.1.26.dist-info → sycommon_python_lib-0.1.38.dist-info}/WHEEL +0 -0
- {sycommon_python_lib-0.1.26.dist-info → sycommon_python_lib-0.1.38.dist-info}/entry_points.txt +0 -0
- {sycommon_python_lib-0.1.26.dist-info → sycommon_python_lib-0.1.38.dist-info}/top_level.txt +0 -0
sycommon/logging/kafka_log.py
CHANGED
|
@@ -470,12 +470,22 @@ class SYLogger:
|
|
|
470
470
|
thread_info = SYLogger._get_execution_context()
|
|
471
471
|
|
|
472
472
|
# 构建日志结构,添加线程/协程信息到threadName字段
|
|
473
|
-
request_log = {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
473
|
+
request_log = {}
|
|
474
|
+
if level == "ERROR":
|
|
475
|
+
request_log = {
|
|
476
|
+
"trace_id": str(trace_id) if trace_id else Snowflake.next_id(),
|
|
477
|
+
"message": msg_str,
|
|
478
|
+
"traceback": traceback.format_exc(),
|
|
479
|
+
"level": level,
|
|
480
|
+
"threadName": thread_info
|
|
481
|
+
}
|
|
482
|
+
else:
|
|
483
|
+
request_log = {
|
|
484
|
+
"trace_id": str(trace_id) if trace_id else Snowflake.next_id(),
|
|
485
|
+
"message": msg_str,
|
|
486
|
+
"level": level,
|
|
487
|
+
"threadName": thread_info
|
|
488
|
+
}
|
|
479
489
|
|
|
480
490
|
# 选择日志级别
|
|
481
491
|
_log = ''
|
sycommon/logging/sql_logger.py
CHANGED
|
@@ -13,9 +13,9 @@ class SQLTraceLogger:
|
|
|
13
13
|
def serialize_params(params):
|
|
14
14
|
"""处理特殊类型参数的序列化"""
|
|
15
15
|
if isinstance(params, (list, tuple)):
|
|
16
|
-
return [
|
|
16
|
+
return [serialize_params(p) for p in params]
|
|
17
17
|
elif isinstance(params, dict):
|
|
18
|
-
return {k:
|
|
18
|
+
return {k: serialize_params(v) for k, v in params.items()}
|
|
19
19
|
elif isinstance(params, datetime):
|
|
20
20
|
return params.isoformat()
|
|
21
21
|
elif isinstance(params, Decimal):
|
|
@@ -23,18 +23,15 @@ class SQLTraceLogger:
|
|
|
23
23
|
else:
|
|
24
24
|
return params
|
|
25
25
|
|
|
26
|
-
# 监听 SQL 语句执行后事件(计算耗时并输出日志)
|
|
27
26
|
@event.listens_for(Engine, "after_cursor_execute")
|
|
28
27
|
def after_cursor_execute(
|
|
29
28
|
conn, cursor, statement, parameters, context, executemany
|
|
30
29
|
):
|
|
31
30
|
try:
|
|
32
|
-
# 从连接的 execution_options 中获取开始时间
|
|
33
31
|
start_time = conn._execution_options.get(
|
|
34
32
|
"_start_time", time.time())
|
|
35
33
|
execution_time = (time.time() - start_time) * 1000
|
|
36
34
|
|
|
37
|
-
# 构建 SQL 日志信息
|
|
38
35
|
sql_log = {
|
|
39
36
|
"type": "SQL",
|
|
40
37
|
"statement": statement,
|
|
@@ -46,14 +43,11 @@ class SQLTraceLogger:
|
|
|
46
43
|
except Exception as e:
|
|
47
44
|
SYLogger.error(f"SQL日志处理失败: {str(e)}")
|
|
48
45
|
|
|
49
|
-
# 监听 SQL 执行开始事件(记录开始时间到连接的 execution_options)
|
|
50
46
|
@event.listens_for(Engine, "before_cursor_execute")
|
|
51
47
|
def before_cursor_execute(
|
|
52
48
|
conn, cursor, statement, parameters, context, executemany
|
|
53
49
|
):
|
|
54
50
|
try:
|
|
55
|
-
# 通过连接对象的 execution_options 设置开始时间
|
|
56
|
-
# 这里会创建一个新的执行选项副本,避免修改不可变对象
|
|
57
51
|
conn = conn.execution_options(_start_time=time.time())
|
|
58
52
|
except Exception as e:
|
|
59
53
|
SYLogger.error(f"SQL开始时间记录失败: {str(e)}")
|
|
@@ -31,6 +31,7 @@ class RabbitMQListenerConfig(BaseModel):
|
|
|
31
31
|
durable: bool = Field(True, description="是否持久化")
|
|
32
32
|
auto_delete: bool = Field(False, description="是否自动删除队列")
|
|
33
33
|
auto_parse_json: bool = Field(True, description="是否自动解析JSON消息")
|
|
34
|
+
prefetch_count: int = Field(2, description="mq同时消费数量")
|
|
34
35
|
|
|
35
36
|
class Config:
|
|
36
37
|
"""模型配置"""
|