def get_component_loglevel(self, global_default_loglevel): component_default_loglevel = global_default_loglevel try: level = yield self.etcd_client.get(self.component_config_path) if level is not None: level_int = string_to_int(str(level, 'utf-8')) if level_int == 0: self.log.warn( "Unsupported loglevel at component config path", level) else: component_default_loglevel = level self.log.debug("Retrieved component default loglevel", component_default_loglevel) except KeyError: self.log.warn("Failed to retrive default component loglevel") if component_default_loglevel == "": component_default_loglevel = GLOBAL_DEFAULT_LOGLEVEL.encode( 'utf-8') returnValue(component_default_loglevel)
def process_log_config_change(self): self.global_default_level = self.get_global_config() self.loglevel = string_to_int( self.get_component_config(self.global_default_level)) current_log_hash = hash(self.loglevel) if LogController.active_log_hash != current_log_hash: LogController.active_log_hash = current_log_hash update_logging(LogController.instance_id, None, verbosity_adjust=self.loglevel)
def __init__(self): self.args = args = parse_args() self.config = load_config(args) # log levels in python are: # 1 - DEBUG => verbosity_adjust = 10 # 2 - INFO => verbosity_adjust = 20 # 3 - WARNING => verbosity_adjust = 30 # 4 - ERROR => verbosity_adjust = 40 # 5 - CRITICAL => verbosity_adjust = 50 verbosity_adjust = string_to_int(str(args.log_level)) if verbosity_adjust == 0: raise ValueError("Invalid loglevel is given: " + str(args.log_level)) sys.exit(1) self.log = setup_logging(self.config.get('logging', {}), args.instance_id, verbosity_adjust=verbosity_adjust) self.log.info('container-number-extractor', regex=args.container_name_regex) self.build_info = get_build_info() self.log.info('OpenONU-Adapter-Version', build_version=self.build_info) if not args.no_banner: print_banner(self.log) self.etcd_host = str(args.etcd).split(':')[0] self.etcd_port = str(args.etcd).split(':')[1] self.controller = LogController(self.etcd_host, self.etcd_port) self.adapter = None # Create a unique instance id using the passed-in instance id and # UTC timestamp current_time = arrow.utcnow().timestamp self.instance_id = self.args.instance_id + '_' + str(current_time) self.core_topic = str(args.core_topic) self.adapter_topic = str(args.adapter_topic) self.event_topic = str(args.event_topic) self.listening_topic = "%s_%s" % (args.name, args.current_replica) self.id = "%s_%s" % (args.name, args.current_replica) self.startup_components() if not args.no_heartbeat: self.start_kafka_cluster_heartbeat(self.instance_id)
def process_log_config_change(self): self.log.debug("Processing log config change") global_default_level = yield self.get_global_loglevel() level = yield self.get_component_loglevel(global_default_level) level_int = string_to_int(str(level, 'utf-8')) current_log_level = level_int if LogController.active_log_level != current_log_level: LogController.active_log_level = current_log_level self.log.debug("Applying updated loglevel") update_logging(LogController.instance_id, None, verbosity_adjust=level_int) else: self.log.debug("Loglevel not updated")
def get_global_loglevel(self): global_default_loglevel = "" try: level = yield self.etcd_client.get(self.global_config_path) if level is not None: level_int = string_to_int(str(level, 'utf-8')) if level_int == 0: self.log.warn("Unsupported loglevel at global config path", level) else: global_default_loglevel = level self.log.debug("Retrieved global default loglevel", global_default_loglevel) except KeyError: self.log.warn("Failed to retrive default global loglevel") returnValue(global_default_loglevel)