Skip to content

Commit

Permalink
Use the non-deprecated datetime.fromtimestamp method and fix some sma…
Browse files Browse the repository at this point in the history
…ll linting errors (#21)

Co-authored-by: Petr Heinz <[email protected]>
  • Loading branch information
RubenVanEldik and PetrHeinz authored Jan 12, 2024
1 parent b291afa commit d40d73c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions logtail/frame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
from __future__ import print_function, unicode_literals
from datetime import datetime
from datetime import datetime, timezone

from os import path
import __main__
Expand All @@ -11,10 +11,8 @@ def create_frame(record, message, context, include_extra_attributes=False):
if "request" in r and not isinstance(r["request"], (dict, list, bool, int, float, str)) :
del r["request"]
frame = {}
# Python 3 only solution if we ever drop Python 2.7
# frame['dt'] = datetime.utcfromtimestamp(r['created']).replace(tzinfo=timezone.utc).isoformat()
frame['dt'] = "{}+00:00".format(datetime.utcfromtimestamp(r['created']).isoformat())
frame['level'] = level = _levelname(r['levelname'])
frame['dt'] = datetime.fromtimestamp(r['created'], timezone.utc).isoformat()
frame['level'] = _levelname(r['levelname'])
frame['severity'] = int(r['levelno'] / 10)
frame['message'] = message
frame['context'] = ctx = {}
Expand Down Expand Up @@ -47,7 +45,7 @@ def _parse_custom_events(record, include_extra_attributes):
default_keys = {
'args', 'asctime', 'created', 'exc_info', 'exc_text', 'pathname',
'funcName', 'levelname', 'levelno', 'lineno', 'module', 'msecs',
'message', 'msg', 'name', 'pathname', 'process', 'processName',
'message', 'msg', 'name', 'process', 'processName',
'relativeCreated', 'thread', 'threadName'
}
events = {}
Expand Down
1 change: 0 additions & 1 deletion logtail/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def emit(self, record):
# Only raised when not blocking, which means that extra events
# should be dropped.
self.dropcount += 1
pass
except Exception as e:
if self.raise_exceptions:
raise e
3 changes: 1 addition & 2 deletions tests/test_flusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ def _setup_worker(self, uploader=None):
return pipe, uploader, fw

def test_is_thread(self):
pipe, uploader, fw = self._setup_worker()
_, _, fw = self._setup_worker()
self.assertIsInstance(fw, threading.Thread)

def test_flushes_when_queue_is_full(self):
first_frame = list(range(self.buffer_capacity))
second_frame = list(range(self.buffer_capacity, self.buffer_capacity * 2))
self.calls = 0
self.flush_interval = 1000

Expand Down

0 comments on commit d40d73c

Please sign in to comment.