emit different logs in different format based on condition like security events, normal software operation events etc to the std out

I am stuck at situation where i have to
emit logs in different format based on condition like security events, normal software operation events etc to the std out.
example
lets say

  1. security events like authentication failure/success should start
    like SEC EVENT,LEVEL, DATETIME, MESSAGE
  2. normal events should start
    like LEVEL, DATETIME, MESSAGE

I tried using formatter and Filters but all these make decision at the time when my custom logger class is initialized, I need to make that decision during execution time

example:

log = CustomLogClass()

log.info("msg") # this should emit in some format
log.sec_info() # this should emit in other format

2

what is suggested in the comments will be something similar to this:

class CustomLogClass:
    def __init__(self):
        self.normal_logger = self._create_logger('normal_logger', 
                                                 '%(levelname)s, %(asctime)s, %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
        self.sec_logger = self._create_logger('sec_logger'),
                                              '%(levelname)s, %(asctime)s, %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    
    def _create_logger(self, name, log_format, level=logging.INFO):
        # Create a new logger with the specified name
        logger = logging.getLogger(name)
        logger.setLevel(level)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(log_format, datefmt='%Y-%m-%d %H:%M:%S')
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        return logger

    def info(self, message):
        """Logs a normal event."""
        self.normal_logger.info(message)

    def sec_info(self, message):
        """Logs a security event."""
        self.sec_logger.info(message)

This is what I meant in my comment:

 import logging


class CustomLogClass:
    logger1 = logging.getLogger('logger1')
    logger1.setLevel(logging.INFO)
    formatter1 = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    console_handler1 = logging.StreamHandler()
    console_handler1.setFormatter(formatter1)
    logger1.addHandler(console_handler1)

    # Configure the second logger with a different format
    logger2 = logging.getLogger('logger2')
    logger2.setLevel(logging.DEBUG)
    formatter2 = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    console_handler2 = logging.StreamHandler()
    console_handler2.setFormatter(formatter2)
    logger2.addHandler(console_handler2)

    def log_situation1(self, message):
        self.logger1.info(message)

    def log_situation2(self, message):
        self.logger2.info(message)


custom_logger = CustomLogClass()
is_situation1 = True
if is_situation1:
    custom_logger.log_situation1("situation 1 happened")
else:
    custom_logger.log_situation2("situation 2 happened")

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật