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

Format time like isoformat() would #2

Merged
merged 1 commit into from
Oct 15, 2016
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
3 changes: 2 additions & 1 deletion cee_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def jsonhandler(self, obj):
def format(self, log_record):
record = OrderedDict()

record['time'] = self.formatTime(log_record)
record['time'] = datetime.utcfromtimestamp(log_record.created)

record['msg'] = log_record.getMessage()
record['pid'] = log_record.process
record['tid'] = log_record.thread
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
iso8601==0.1.11
pyflakes==1.2.3
pytest==3.0.1
pytest-flake8==0.6
Expand Down
10 changes: 10 additions & 0 deletions test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import logging

import iso8601

from cee_formatter import CEEFormatter

try:
Expand Down Expand Up @@ -36,3 +38,11 @@ def test_datetime_format():
json_dict = json.loads(json_value)

assert json_dict['d'] == date.isoformat()

# We want to make sure that the time is in full ISO8601 format so
# we don't lose too much precision (it'll be microseconds).
# This assertion can generate a false positive when timestamp has
# a zero microsecond part but I think we can live with it.
serialized_timestamp = json_dict['time']
timestamp = iso8601.parse_date(serialized_timestamp).replace(tzinfo=None)
assert serialized_timestamp == timestamp.isoformat()