Skip to content

Commit

Permalink
Caddy: timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Jan 29, 2024
1 parent e916813 commit e6e4d00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions import_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,10 @@ def get(self, key):
raise BaseFormatException()

def get_all(self,):
self.json['date'] = datetime.datetime.fromtimestamp(self.json['ts']).strftime(self.date_format)
self.json['timezone'] = ''
tz = datetime.timezone.utc
date = datetime.datetime.fromtimestamp(self.json['ts'], tz=tz)
self.json['date'] = date.strftime(self.date_format)
self.json['timezone'] = date.strftime('%z')
self.json['length'] = str(self.json['size'])
self.json['status'] = str(self.json['status'])
self.json['generation_time_milli'] = str(self.json['duration'] * 1000.)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ def check_traefik_json_groups(groups):
def check_caddy_json_groups(groups):
assert groups['ts'] == 1703373474.8155608
assert groups['duration'] == 0.001335486
assert groups['date'] == '2023-12-24T00:17:54.815561'
assert groups['date'] == '2023-12-23T23:17:54.815561'
assert groups['timezone'] == '+0000'
assert groups['generation_time_milli'] == '1.3354860000000002'
assert groups['host'] == 'example.com'
assert groups['ip'] == '1.2.3.4'
Expand Down Expand Up @@ -510,7 +511,7 @@ def test_caddy_json_parsing():
assert hits[0]['host'] == 'foo'
assert hits[0]['filename'] == 'logs/caddy_json.log'
assert hits[0]['is_redirect'] == False
assert hits[0]['date'] == datetime.datetime(2023, 12, 24, 0, 17, 54, 815561)
assert hits[0]['date'] == datetime.datetime(2023, 12, 23, 23, 17, 54, 815561)
assert hits[0]['lineno'] == 0
assert hits[0]['ip'] == '1.2.3.4'
assert hits[0]['path'] == '/beta/'
Expand Down

0 comments on commit e6e4d00

Please sign in to comment.