monorepo-microservice-rbac/apps/services/alg/app.py

26 lines
805 B
Python
Raw Normal View History

2023-09-13 18:10:23 +08:00
from pynats2 import NATSClient
2023-09-14 13:59:50 +08:00
from datetime import datetime,timedelta
2023-09-13 18:10:23 +08:00
import json
2023-09-13 17:40:06 +08:00
2023-09-14 14:05:21 +08:00
# nats-server配置信息
NATS_PATTERN = "alg.test"
NATS_SERVER = "nats://localhost:4222"
2023-09-13 18:10:23 +08:00
def publish_to_nats():
2023-09-14 14:05:21 +08:00
timestamp = (datetime.utcnow() + timedelta(hours=8)).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
2023-09-14 13:59:50 +08:00
standardLog = {
2023-09-14 14:05:21 +08:00
"timestamp": timestamp,
2023-09-14 13:59:50 +08:00
"level": 'INFO', # DEBUG、INFO、WARNING、ERROR、CRITICAL等级别
"name": 'alg.slice',# 日志生产的模块、服务
"message": "算法版本:$1,分割结果:$2",# 日志记录模板
"customFields": {
"$1": "1.0.0",
"$2": True
},
2023-09-13 18:10:23 +08:00
}
2023-09-14 14:05:21 +08:00
with NATSClient(NATS_SERVER) as client:
client.publish(NATS_PATTERN, payload=json.dumps(standardLog).encode('utf-8'))
2023-09-13 17:40:06 +08:00
2023-09-13 18:10:23 +08:00
if __name__ == '__main__':
2023-09-14 13:59:50 +08:00
publish_to_nats()