Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the non-deprecated datetime.fromtimestamp method and fix some small linting errors #21

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading