Skip to content

Commit

Permalink
Add support for additional timestamp format (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-shirshov authored and lguohan committed Feb 21, 2018
1 parent 19cb85e commit 2f2e398
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ansible/library/extract_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,18 @@ def extract_number(s):


def convert_date(s):
str_date = re.findall(r'^\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}\.?\d*', s)[0]
dt = None
try:
dt = datetime.strptime(str_date, '%b %d %X.%f')
except ValueError:
pass
if dt is None:
dt = datetime.strptime(str_date, '%b %d %X')
re_result = re.findall(r'^\S{3}\s{1,2}\d{1,2} \d{2}:\d{2}:\d{2}\.?\d*', s)
if len(re_result) > 0:
str_date = re_result[0]
try:
dt = datetime.strptime(str_date, '%b %d %X.%f')
except ValueError:
dt = datetime.strptime(str_date, '%b %d %X')
else:
re_result = re.findall(r'^\d{4}-\d{2}-\d{2}\.\d{2}:\d{2}:\d{2}\.\d{6}', s)
str_date = re_result[0]
dt = datetime.strptime(str_date, '%Y-%m-%d.%X.%f')

return dt

Expand Down

0 comments on commit 2f2e398

Please sign in to comment.