2018-03-27 14:30:46 -04:00
|
|
|
"""Custom formatters for the logging handlers."""
|
2015-06-22 20:18:10 -04:00
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
2021-03-04 15:31:14 -05:00
|
|
|
class TimestampFormatter(logging.Formatter):
|
|
|
|
|
"""Timestamp formatter for log messages.
|
2018-03-27 14:30:46 -04:00
|
|
|
|
2021-03-04 15:31:14 -05:00
|
|
|
Timestamp format example: 13:27:03.246Z
|
2015-06-22 20:18:10 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def formatTime(self, record, datefmt=None):
|
2018-03-27 14:30:46 -04:00
|
|
|
"""Return formatted time."""
|
2015-06-22 20:18:10 -04:00
|
|
|
converted_time = self.converter(record.created)
|
|
|
|
|
|
|
|
|
|
if datefmt is not None:
|
|
|
|
|
return time.strftime(datefmt, converted_time)
|
|
|
|
|
|
2021-03-04 15:31:14 -05:00
|
|
|
formatted_time = time.strftime("%H:%M:%S", converted_time)
|
|
|
|
|
return "%s.%03dZ" % (formatted_time, record.msecs)
|