Skip to content

Commit 688155b

Browse files
author
Vasileios Karakasis
committed
Add full RFC3339 compliance to time format (fixes)
1 parent bf3bbef commit 688155b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

reframe/core/logging.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,10 @@ def close(self):
136136
def _format_time_rfc3339(timestamp, datefmt):
137137
tz_suffix = time.strftime('%z', timestamp)
138138
tz_rfc3339 = tz_suffix[:-2] + ':' + tz_suffix[-2:]
139-
return time.strftime(datefmt, timestamp).replace(':z', tz_rfc3339)
139+
return time.strftime(datefmt, timestamp).replace('%:z', tz_rfc3339)
140140

141141

142142
class RFC3339Formatter(logging.Formatter):
143-
def __init__(self, fmt=None, datefmt=None, style='%'):
144-
super().__init__(fmt, datefmt, style)
145-
146-
# Formatter objects store fmt in `_fmt`, but we use our own variable
147-
# here just to stay on the safe side if Formatter's implementation
148-
# changes
149-
self.__fmt = fmt
150-
151143
def formatTime(self, record, datefmt=None):
152144
datefmt = datefmt or self.default_time_format
153145
if '%:z' not in datefmt:
@@ -156,12 +148,18 @@ def formatTime(self, record, datefmt=None):
156148
timestamp = self.converter(record.created)
157149
return _format_time_rfc3339(timestamp, datefmt)
158150

159-
def usesTime(self):
160-
# Extend usesTime() so as to trigger time formatting for our own
161-
# custom time formats
162-
return (super().usesTime() or
163-
'%(check_job_completion_time)' in self.__fmt or
164-
'{check_job_completion_time}' in self.__fmt)
151+
def format(self, record):
152+
datefmt = self.datefmt or self.default_time_format
153+
try:
154+
if record.check_job_completion_time is not None:
155+
ct = self.converter(record.check_job_completion_time)
156+
record.check_job_completion_time = _format_time_rfc3339(
157+
ct, datefmt
158+
)
159+
except AttributeError:
160+
pass
161+
162+
return super().format(record)
165163

166164

167165
def load_from_dict(logging_config):

0 commit comments

Comments
 (0)