Skip to content

Commit b328431

Browse files
heitorlessaMichael Brewer
and
Michael Brewer
authored
Update aws_lambda_powertools/logging/formatter.py
Co-authored-by: Michael Brewer <[email protected]>
1 parent 4345d8b commit b328431

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

aws_lambda_powertools/logging/formatter.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,16 @@ def format(self, record: logging.LogRecord) -> str: # noqa: A003
131131
return self.json_serializer(formatted_log)
132132

133133
def formatTime(self, record: logging.LogRecord, datefmt: Optional[str] = None) -> str:
134-
# NOTE: Pyhton time.strftime doesn't provide msec directives
135-
# so we create a custom one (%F) and replace logging record ts
136-
# Reason 2 is that std logging doesn't support msec after TZ
137134
record_ts = self.converter(record.created)
138135
if datefmt:
139-
ts_formatted = time.strftime(datefmt, record_ts)
140-
else:
141-
msec = "%03d" % record.msecs
142-
custom_fmt = self.default_time_format.replace(self.custom_ms_time_directive, msec)
143-
ts_formatted = time.strftime(custom_fmt, record_ts)
144-
return ts_formatted
136+
return time.strftime(datefmt, record_ts)
137+
138+
# NOTE: Python `time.strftime` doesn't provide msec directives
139+
# so we create a custom one (%F) and replace logging record ts
140+
# Reason 2 is that std logging doesn't support msec after TZ
141+
msecs = "%03d" % record.msecs
142+
custom_fmt = self.default_time_format.replace(self.custom_ms_time_directive, msecs)
143+
return time.strftime(custom_fmt, record_ts)
145144

146145
def append_keys(self, **additional_keys):
147146
self.log_format.update(additional_keys)

0 commit comments

Comments
 (0)