Source code for easyplayer.main

import logging, logging.config, logging.handlers
from logging import getLogger

from circuits.app import Daemon
from circuits import Debugger

from easyplayer.core import App
from .config import Config
from .settings import LOGGING, get_file_handler, CONFIG_FILES

def setup_logging(config):

    logconfig = LOGGING.copy()

    if "logfile" in config and config['logfile']:
        logconfig['handlers']['file'] = get_file_handler(config['logfile'])
        for k, d in logconfig['loggers'].items():
            d['handlers'].append('file')
        logconfig['root']['handlers'].append('file')

    for k,v in [item for item in config.items() if item[0].endswith('_log')]:
        if v:
            module = k.replace('_log', '')
            lk = '.'.join(['easyplayer', module])
            d = logconfig['loggers'].get(lk, {
                    "level": "DEBUG",
                    "handlers": [],
                    "propagate": False
                })
            hk = module + '_file'
            # set handler
            logconfig['handlers'][hk] = get_file_handler(v)
            # set logger
            d['handlers'].append(hk)
            logconfig['loggers'][lk] = d

    logging.config.dictConfig(LOGGING)
    logger = getLogger(__name__)

    return logger


[docs]def main(): """ main starting point of the application, reads configuration file and setup logging """ config = Config() logger = setup_logging(config) if config.file: logger.info('Configuration file from %s', config.file) app = App(config) if config["debug"]: logger.debug('Attaching debugger.') Debugger( logger=logger, events=config["verbose"], ).register(app) if config["daemon"]: Daemon(config["pidfile"]).register(app) app.run() else: logger.error('Configuration file not found in %s, %s nor %s', *CONFIG_FILES)
if __name__ == "__main__": main()