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