def _setup(): # Set up logger which logs everything which happens during and before config # parsing to sys.stdout logging.setup(DEFAULT_LOGGING_CONF_PATH) # 1. parse config args config.parse_args() # 2. setup logging. logging.setup(cfg.CONF.sensorcontainer.logging) # 3. all other setup which requires config to be parsed and logging to # be correctly setup. username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None db_setup(cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port, username=username, password=password) register_exchanges() register_common_signal_handlers() # 4. Register internal triggers # Note: We need to do import here because of a messed up configuration # situation (this module depends on configuration being parsed) from st2common.triggers import register_internal_trigger_types register_internal_trigger_types()
def _setup(): # Set up logger which logs everything which happens during and before config # parsing to sys.stdout logging.setup(DEFAULT_LOGGING_CONF_PATH) # 1. parse config args config.parse_args() # 2. setup logging. logging.setup(cfg.CONF.sensorcontainer.logging) # 3. all other setup which requires config to be parsed and logging to # be correctly setup. username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None db_setup(cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port, username=username, password=password) register_exchanges() register_common_signal_handlers() # 4. Register internal triggers register_internal_trigger_types()
def _setup(argv): config.parse_args() # 2. setup logging log_level = logging.DEBUG logging.basicConfig(format='%(asctime)s %(levelname)s [-] %(message)s', level=log_level) if not cfg.CONF.verbose: # Note: We still want to print things at the following log levels: INFO, ERROR, CRITICAL exclude_log_levels = [logging.AUDIT, logging.DEBUG] handlers = logging.getLoggerClass().manager.root.handlers for handler in handlers: handler.addFilter(LogLevelFilter(log_levels=exclude_log_levels)) # 3. all other setup which requires config to be parsed and logging to # be correctly setup. username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None db_setup(cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port, username=username, password=password) register_exchanges()
def _setup(): # Set up logger which logs everything which happens during and before config # parsing to sys.stdout logging.setup(DEFAULT_LOGGING_CONF_PATH) # 1. parse args to setup config. config.parse_args() # 2. setup logging. logging.setup(cfg.CONF.notifier.logging) # 3. all other setup which requires config to be parsed and logging to # be correctly setup. username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None db_setup(cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port, username=username, password=password) register_exchanges()
def _setup(argv): config.parse_args() log_level = logging.DEBUG logging.basicConfig(format='%(asctime)s %(levelname)s [-] %(message)s', level=log_level) if not cfg.CONF.verbose: # Note: We still want to print things at the following log levels: INFO, ERROR, CRITICAL exclude_log_levels = [logging.AUDIT, logging.DEBUG] handlers = logging.getLoggerClass().manager.root.handlers for handler in handlers: handler.addFilter(LogLevelFilter(log_levels=exclude_log_levels)) db_setup() register_exchanges()
def setup(service, config, setup_db=True, register_mq_exchanges=True, register_signal_handlers=True): """ Common setup function. Currently it performs the following operations: 1. Parses config and CLI arguments 2. Establishes DB connection 3. Set log level for all the loggers to DEBUG if --debug flag is present 4. Registers RabbitMQ exchanges 5. Registers common signal handlers :param service: Name of the service. :param config: Config object to use to parse args. """ # Set up logger which logs everything which happens during and before config # parsing to sys.stdout logging.setup(DEFAULT_LOGGING_CONF_PATH) # Parse args to setup config. config.parse_args() config_file_paths = cfg.CONF.config_file config_file_paths = [os.path.abspath(path) for path in config_file_paths] LOG.debug('Using config files: %s', ','.join(config_file_paths)) # Setup logging. logging_config_path = config.get_logging_config_path() logging_config_path = os.path.abspath(logging_config_path) LOG.debug('Using logging config: %s', logging_config_path) logging.setup(logging_config_path) if cfg.CONF.debug: set_log_level_for_all_loggers(level=stdlib_logging.DEBUG) # All other setup which requires config to be parsed and logging to # be correctly setup. if setup_db: db_setup() if register_mq_exchanges: register_exchanges() if register_signal_handlers: register_common_signal_handlers()
def main(): _setup() register_exchanges()