Skip to content

Commit

Permalink
update timestamp into seconds when migration from es with time-reference
Browse files Browse the repository at this point in the history
Change-Id: I3bb534411984f07d0abf60c37ff2393d45dca249

update timestamp into seconds when migration from es with time-reference

Change-Id: If56812bb2c5c34628ad6c74dc9d261e2812a14c9
  • Loading branch information
Miaodric committed Aug 8, 2024
1 parent 5787e5f commit 355fffe
Show file tree
Hide file tree
Showing 2 changed files with 369 additions and 365 deletions.
17 changes: 10 additions & 7 deletions aliyun/log/logitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ class LogItem(object):
""" LogItem used to present a log, it contains log time and multiple
key/value pairs to present the log contents.
:type timestamp: int
:type timestamp: int with seconds as unit
:param timestamp: time of the log item, the default time is the now time.
:type contents: tuple(key-value) list
:param contents: the data of the log item, including many (key,value) pairs.
"""

def __init__(self, timestamp=None, time_nano_part=None, contents=None):
nano_time = int(time.time()* 10**9)
self.timestamp = int(timestamp) if timestamp else int(nano_time / 1000000000)
self.time_nano_part= int(time_nano_part) if time_nano_part else int(nano_time%1000000000)
nano_time = int(time.time() * 10**9)
self.timestamp_seconds = int(timestamp) if timestamp else int(nano_time / 1000000000)
# milliseconds
if self.timestamp_seconds > 1e10:
self.timestamp_seconds = int(self.timestamp_seconds / 1000.0)
self.time_nano_part = int(time_nano_part) if time_nano_part else int(nano_time % 1000000000)
self.contents = copy.deepcopy(contents) if contents else []

def push_back(self, key, value):
Expand Down Expand Up @@ -56,7 +59,7 @@ def get_time(self):
:return: int, log time
"""
return self.timestamp
return self.timestamp_seconds

def get_time_nano_part(self):
""" Get log time nano part
Expand All @@ -70,7 +73,7 @@ def set_time(self, timestamp):
:type timestamp: int
:param timestamp: log time
"""
self.timestamp = int(timestamp)
self.timestamp_seconds = int(timestamp)

def set_time_nano_part(self, time_nano_part):
""" Set log time nano part
Expand All @@ -80,5 +83,5 @@ def set_time_nano_part(self, time_nano_part):
self.time_nano_part = int(time_nano_part)

def log_print(self):
print('time', self.timestamp)
print('time', self.timestamp_seconds)
print('contents', self.contents)
Loading

0 comments on commit 355fffe

Please sign in to comment.