class MyFormatter(logging.Formatter):
    err_fmt = 'ERROR: %(msg)s'
dbg_fmt = 'DBG: %(module)s: %(lineno)d: %(msg)s'
info_fmt = '%(msg)s'

def __init__(self, fmt='%(levelno)s: %(msg)s'):
    logging.Formatter.__init__(self, fmt)

def format(self, record):
    format_orig = self._fmt
if record.levelno == logging.DEBUG:
    self._fmt = MyFormatter.dbg_fmt
elif record.levelno == logging.INFO:
    self._fmt = MyFormatter.info_fmt
elif record.levelno == logging.ERROR:
    self._fmt = MyFormatter.err_fmt
result = logging.Formatter.format(self, record)
self._fmt = format_orig
return result
Can Python's logging format be modified depending on the message log level?