def format(self, record):
# Save the original format configured by the user
# when the logger formatter was instantiated
format_orig = self._fmt
# Replace the original format with one customized by logging level
if record.levelno == logging.DEBUG:
self._fmt = MyFormatter.timestamp + " " + MyFormatter.debug_char + " " + MyFormatter.message
elif record.levelno == logging.INFO:
self._fmt = MyFormatter.timestamp + " " + MyFormatter.info_char + " " + MyFormatter.message
elif record.levelno == logging._levelNames["SUCCESS"]:
self._fmt = MyFormatter.timestamp + " " + MyFormatter.success_char + " " + MyFormatter.message
elif record.levelno == logging._levelNames["START"]:
self._fmt = MyFormatter.timestamp + " " + MyFormatter.start_char + " " + MyFormatter.message
elif record.levelno == logging.WARNING:
self._fmt = MyFormatter.timestamp + " " + MyFormatter.warning_char + " " + MyFormatter.message
elif record.levelno == logging.ERROR:
self._fmt = MyFormatter.timestamp + " " + MyFormatter.error_char + " " + MyFormatter.message
# Call the original formatter class to do the grunt work
result = logging.Formatter.format(self, record)
# Restore the original format configured by the user
self._fmt = format_orig
return result
# -----------------------------------------------------------------
评论列表
文章目录