# Path: pushkin/config.py
# DATABASE_CONFIG_SECTION = 'Database'
# SERVER_SPECIFIC_CONFIG_SECTION = 'ServerSpecific'
# EVENT_CONFIG_SECTION = 'Event'
# LOG_CONFIG_SECTION = 'Log'
# SERVER_CONFIG_SECTION = 'Server'
# MESSENGER_CONFIG_SECTION = 'Messenger'
# REQUEST_PROCESSOR_CONFIG_SECTION = 'RequestProcessor'
# SENDER_CONFIG_SECTION = 'Sender'
# REQUEST_HANDLER_SECTION = 'RequestHandler'
# def init(configuration_file):


import logging
import os
from pushkin import config
from util.multiprocesslogging import LogCollector, create_multiprocess_logger

request_processor = None
event_handler_manager = None
log_queue = None
PERSIST_LOGGER_PREFFIX = 'persist_'
main_logger = None
notification_logger = None
message_blacklist = None

"""This module is used as a holder for global state in server process"""

def setup_loggers():
    """Should be called before using loggers"""
    global log_queue
    global PERSIST_LOGGER_PREFFIX
    global main_logger
    global notification_logger

    # setup folders
    if not os.path.exists(os.path.dirname(config.main_log_path)):
        os.makedirs(os.path.dirname(config.main_log_path))
    if not os.path.exists(os.path.dirname(config.notification_log_path)):
        os.makedirs(os.path.dirname(config.notification_log_path))

    # setup loggers
    create_multiprocess_logger(logger_name=config.main_logger_name, log_level=config.main_log_level,
                               persist_logger_name=PERSIST_LOGGER_PREFFIX + config.main_logger_name,
                               log_format='%(asctime)s %(levelname)s %(message)s', log_queue=log_queue,
                               log_file_path=config.main_log_file_path, when_to_rotate="midnight",
                               keep_log_days=config.keep_log_days)

# Path: pushkin/config.py
# DATABASE_CONFIG_SECTION = 'Database'
# SERVER_SPECIFIC_CONFIG_SECTION = 'ServerSpecific'
# EVENT_CONFIG_SECTION = 'Event'
# LOG_CONFIG_SECTION = 'Log'
# SERVER_CONFIG_SECTION = 'Server'
# MESSENGER_CONFIG_SECTION = 'Messenger'
# REQUEST_PROCESSOR_CONFIG_SECTION = 'RequestProcessor'
# SENDER_CONFIG_SECTION = 'Sender'
# REQUEST_HANDLER_SECTION = 'RequestHandler'
# def init(configuration_file):


# Path: pushkin/context.py
import logging
import os
from pushkin import config
from util.multiprocesslogging import LogCollector, create_multiprocess_logger


request_processor = None
event_handler_manager = None
log_queue = None
PERSIST_LOGGER_PREFFIX = 'persist_'
main_logger = None
notification_logger = None
message_blacklist = None

"""This module is used as a holder for global state in server process"""

def setup_loggers():
    """Should be called before using loggers"""
    global log_queue
    global PERSIST_LOGGER_PREFFIX
    global main_logger
    global notification_logger

    # setup folders
    if not os.path.exists(os.path.dirname(config.main_log_path)):
        os.makedirs(os.path.dirname(config.main_log_path))
    if not os.path.exists(os.path.dirname(config.notification_log_path)):
        os.makedirs(os.path.dirname(config.notification_log_path))

    # setup loggers
    create_multiprocess_logger(logger_name=config.main_logger_name, log_level=config.main_log_level,
                               persist_logger_name=PERSIST_LOGGER_PREFFIX + config.main_logger_name,
                               log_format='%(asctime)s %(levelname)s %(message)s', log_queue=log_queue,
                               log_file_path=config.main_log_file_path, when_to_rotate="midnight",
                               keep_log_days=config.keep_log_days)

    main_logger = logging.getLogger(config.main_logger_name)