|
@@ -5,6 +5,7 @@ import json
|
|
|
import datetime
|
|
|
from aliyun.log import LogClient, PutLogsRequest, LogItem
|
|
|
|
|
|
+
|
|
|
class LogService:
|
|
|
def __init__(self, endpoint, access_key_id, access_key_secret, project, logstore):
|
|
|
self.client = LogClient(endpoint, access_key_id, access_key_secret)
|
|
@@ -35,7 +36,7 @@ class LogService:
|
|
|
|
|
|
def _put_log(self, contents: dict):
|
|
|
timestamp = int(time.time())
|
|
|
- contents['datetime'] = datetime.datetime.now().__str__()
|
|
|
+ contents["datetime"] = datetime.datetime.now().__str__()
|
|
|
safe_items = [
|
|
|
(str(k), json.dumps(v) if isinstance(v, (dict, list)) else str(v))
|
|
|
for k, v in contents.items()
|
|
@@ -43,5 +44,7 @@ class LogService:
|
|
|
log_item = LogItem(timestamp=timestamp, contents=safe_items)
|
|
|
print(type(log_item))
|
|
|
print(log_item)
|
|
|
- req = PutLogsRequest(self.project, self.logstore, topic="", source="", logitems=[log_item])
|
|
|
+ req = PutLogsRequest(
|
|
|
+ self.project, self.logstore, topic="", source="", logitems=[log_item]
|
|
|
+ )
|
|
|
self.client.put_logs(req)
|