Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
make jsonlogger python2 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Oct 29, 2020
1 parent bce3093 commit 91d2e9d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions logzero/jsonlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
This library is provided to allow standard python logging
to output log data as JSON formatted strings
'''
import sys
import logging
import json
import re
from datetime import date, datetime, time, timezone
import traceback
import importlib
from datetime import date, datetime, time

if sys.version_info >= (3, ):
from datetime import timezone
tz = timezone.utc
else:
tz = None


from inspect import istraceback

Expand Down Expand Up @@ -160,7 +168,7 @@ def add_fields(self, log_record, record, message_dict):

if self.timestamp:
key = self.timestamp if type(self.timestamp) == str else 'timestamp'
log_record[key] = datetime.fromtimestamp(record.created, tz=timezone.utc)
log_record[key] = datetime.fromtimestamp(record.created, tz=tz)

def process_log_record(self, log_record):
"""
Expand Down

0 comments on commit 91d2e9d

Please sign in to comment.