Loggers
import logging.handlers
logger = logging.getLogger("loggers")
class CustomFormatter(logging.Formatter):
def format(self, record):
return f"{record.levelname} | {record.filename}:{record.levelno}:{record.lineno} | {record.msg}"
class CustomFilter(logging.Filter):
def filter(self, record):
if record.msg is not None and record.msg.startswith('2'):
return False
else:
return True
def create_custom_handler():
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
handler.setFormatter(CustomFormatter())
return handler
logger.setLevel(logging.ERROR)
logger.addHandler(create_custom_handler())
logger.debug('1')
logger.info('2')
logger.warning('3')
logger.error('4')
logger.fatal('5')