Skip to content

Commit

Permalink
Merge pull request #80 from mik3y/mikey/time
Browse files Browse the repository at this point in the history
bugfix: use `time.monotonic()` when calculating intervals
  • Loading branch information
s-scheele-simonsen authored Sep 14, 2023
2 parents d4d8738 + ffa4461 commit 958a3aa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions axiom/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, client: Client, dataset: str, level=NOTSET, interval=1):
self.client = client
self.dataset = dataset
self.buffer = []
self.last_run = time.time()
self.last_run = time.monotonic()
self.interval = interval

# register flush on exit,
Expand All @@ -34,12 +34,12 @@ def __init__(self, client: Client, dataset: str, level=NOTSET, interval=1):
def emit(self, record):
"""emit sends a log to Axiom."""
self.buffer.append(record.__dict__)
if len(self.buffer) >= 1000 or time.time() - self.last_run > self.interval:
if len(self.buffer) >= 1000 or time.monotonic() - self.last_run > self.interval:
self.flush()

def flush(self):
"""flush sends all logs in the logcache to Axiom."""
self.last_run = time.time()
self.last_run = time.monotonic()
if len(self.buffer) == 0:
return
self.client.ingest_events(self.dataset, self.buffer)
Expand Down

0 comments on commit 958a3aa

Please sign in to comment.