import logging
from logging.handlers import SysLogHandler
from django.conf import settings
from sys import stdout

LOG_AREA_PAYMENT = 'payment'

payment_logger = logging.getLogger(LOG_AREA_PAYMENT)

def init_logging():
    global manage_logger, payment_logger
    """ Initialize the different loggers used in the application """
    # create formatter
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    # default log
    stdoutHandler = logging.StreamHandler(stdout)
    stdoutHandler.setLevel(logging.DEBUG)
    stdoutHandler.setFormatter(formatter)
    logging.getLogger().addHandler(stdoutHandler)
    default_log_handler = SysLogHandler("/dev/log", "local0")
    default_log_handler.setLevel(logging.DEBUG)
    default_log_handler.setFormatter(formatter)
    logging.getLogger().addHandler(default_log_handler)
    
    # payment log
    payment_logger = logging.getLogger(LOG_AREA_PAYMENT)
    payment_logger.setLevel(logging.DEBUG)
    payment_handler = SysLogHandler("/dev/log", "local1")
    payment_handler.setFormatter(formatter)
    payment_logger.addHandler(payment_handler)

logInitDone = False

if not logInitDone:
    logInitDone = True
    init_logging()