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

21 lines
673 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-13 18:10:23 +08:00
def publish_to_nats():
2023-09-14 13:59:50 +08:00
standardLog = {
"timestamp": (datetime.utcnow()+timedelta(hours=8)).strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
"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
}
with NATSClient() as client:
2023-09-14 13:59:50 +08:00
client.publish("alg.test", 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()