当前位置: 首页>>代码示例>>Python>>正文


Python Sandesh.set_logging_params方法代码示例

本文整理汇总了Python中pysandesh.sandesh_base.Sandesh.set_logging_params方法的典型用法代码示例。如果您正苦于以下问题:Python Sandesh.set_logging_params方法的具体用法?Python Sandesh.set_logging_params怎么用?Python Sandesh.set_logging_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysandesh.sandesh_base.Sandesh的用法示例。


在下文中一共展示了Sandesh.set_logging_params方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _sandesh_init

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]
 def _sandesh_init(self, discovery):
     sandesh_instance = Sandesh()
     sandesh.ServiceInstanceList.handle_request =\
         self.sandesh_si_handle_request
     sandesh_instance.init_generator(
         self._module_name, self._hostname, self._node_type_name, 
         self._instance_id, self._args.collectors, 'svc_monitor_context',
         int(self._args.http_server_port), ['cfgm_common', 'svc_monitor.sandesh'],
         discovery)
     sandesh_instance.set_logging_params(
         enable_local_log=self._args.log_local,
         category=self._args.log_category,
         level=self._args.log_level,
         file=self._args.log_file,
         enable_syslog=self._args.use_syslog,
         syslog_facility=self._args.syslog_facility)
     return sandesh_instance
开发者ID:Juniper,项目名称:contrail-dev-controller,代码行数:19,代码来源:logger.py

示例2: JobLogger

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]
class JobLogger(ConfigServiceLogger):

    def __init__(self, args=None, http_server_port=None,
                 sandesh_instance_id=None, sandesh_instance=None):
        self.sandesh_instance_id = sandesh_instance_id
        self._sandesh = sandesh_instance
        module = Module.FABRIC_ANSIBLE
        module_pkg = "job_manager"
        self.context = "job_manager"
        super(JobLogger, self).__init__(
            module, module_pkg, args, http_server_port)

    def sandesh_init(self, http_server_port=None):
        """ Init sandesh """
        if self._sandesh is not None:
            return

        self._sandesh = Sandesh()
        self.redefine_sandesh_handles()
        if not http_server_port:
            http_server_port = self._args.http_server_port

        self._instance_id = self.sandesh_instance_id

        self._sandesh.init_generator(
            self._module_name, self._hostname, self._node_type_name,
            self.sandesh_instance_id, self._args.random_collectors,
            '%s_context' % self.context, int(http_server_port),
            ['cfgm_common'],
            logger_class=self._args.logger_class,
            logger_config_file=self._args.logging_conf,
            config=self._args.sandesh_config)

        self._sandesh.set_logging_params(
            enable_local_log=self._args.log_local,
            category=self._args.log_category,
            level=self._args.log_level,
            file=self._args.log_file,
            enable_syslog=self._args.use_syslog,
            syslog_facility=self._args.syslog_facility)

        VncGreenlet.register_sandesh_handler()

        self._sandesh.trace_buffer_create(name="MessageBusNotifyTraceBuf",
                                          size=1000)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:47,代码来源:logger.py

示例3: KubeManagerLogger

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]

#.........这里部分代码省略.........
        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # WARNING.
    def warning(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_WARN
        logging_fun = log_fun if log_fun else sandesh.KubeManagerWarningLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # NOTICE.
    def notice(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_NOTICE
        logging_fun = log_fun if log_fun else sandesh.KubeManagerNoticeLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # INFO.
    def info(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_INFO
        logging_fun = log_fun if log_fun else sandesh.KubeManagerInfoLog

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # DEBUG.
    def debug(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_DEBUG
        logging_fun = log_fun if log_fun else sandesh.KubeManagerDebugLog

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    def _redefine_sandesh_handles(self):
        """ Register custom introspect handlers. """
        # Register Pod DB introspect handler.
        introspect.PodDatabaseList.handle_request =\
            PodKM.sandesh_handle_db_list_request

        # Register Namespace DB introspect handler.
        introspect.NamespaceDatabaseList.handle_request =\
            NamespaceKM.sandesh_handle_db_list_request

        # Register Service DB introspect handler.
        introspect.ServiceDatabaseList.handle_request =\
            ServiceKM.sandesh_handle_db_list_request

        # Register NetworkPolicy DB introspect handler.
        introspect.NetworkPolicyDatabaseList.handle_request =\
            NetworkPolicyKM.sandesh_handle_db_list_request

        # Register Ingress DB introspect handler.
        introspect.IngressDatabaseList.handle_request =\
            IngressKM.sandesh_handle_db_list_request

    def sandesh_init(self):
        """ Init Sandesh """
        self._sandesh = Sandesh()

        # Register custom sandesh request handlers.
        self._redefine_sandesh_handles()

        # Initialize Sandesh generator.
        self._sandesh.init_generator(
            self._module["name"], self._module["hostname"],
            self._module["node_type_name"], self._module["instance_id"],
            self._args.random_collectors, 'kube_manager_context',
            int(self._args.http_server_port),
            ['cfgm_common', 'kube_manager'],
            logger_class=self._args.logger_class,
            logger_config_file=self._args.logging_conf,
            config=self._args.sandesh_config)

        # Set Sandesh logging params.
        self._sandesh.set_logging_params(
            enable_local_log=self._args.log_local,
            category=self._args.log_category, level=self._args.log_level,
            file=self._args.log_file, enable_syslog=self._args.use_syslog,
            syslog_facility=self._args.syslog_facility)

        # Connect to collector.
        ConnectionState.init(
            self._sandesh, self._module["hostname"], self._module["name"],
            self._module["instance_id"],
            staticmethod(ConnectionState.get_process_state_cb),
            NodeStatusUVE, NodeStatus, self._module["table"])

    def sandesh_uninit(self):
        self._sandesh.uninit()
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:104,代码来源:logger.py

示例4: ConfigServiceLogger

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]
class ConfigServiceLogger(object):

    _LOGGER_LEVEL_TO_SANDESH_LEVEL = {
        logging.CRITICAL: SandeshLevel.SYS_EMERG,
        logging.CRITICAL: SandeshLevel.SYS_ALERT,
        logging.CRITICAL: SandeshLevel.SYS_CRIT,
        logging.ERROR: SandeshLevel.SYS_ERR,
        logging.WARNING: SandeshLevel.SYS_WARN,
        logging.WARNING: SandeshLevel.SYS_NOTICE,
        logging.INFO: SandeshLevel.SYS_INFO,
        logging.DEBUG: SandeshLevel.SYS_DEBUG
    }

    def __init__(self, module, module_pkg, args=None, http_server_port=None):
        self.module_pkg = module_pkg
        if not hasattr(self, 'context'):
            self.context = module_pkg
        self._args = args

        if 'host_ip' in args:
            host_ip = args.host_ip
        else:
            host_ip = socket.gethostbyname(socket.getfqdn())
        node_type = Module2NodeType[module]
        self._module_name = ModuleNames[module]
        self._node_type_name = NodeTypeNames[node_type]
        self.table = "ObjectConfigNode"
        self._instance_id = INSTANCE_ID_DEFAULT
        self._hostname = socket.getfqdn(host_ip)

        # sandesh init
        self.sandesh_init(http_server_port)

    def _get_sandesh_logger_level(self, sandesh_level):
        return self._LOGGER_LEVEL_TO_SANDESH_LEVEL[sandesh_level]

    def log(self, log_msg, level=SandeshLevel.SYS_DEBUG, fun=None):
        if fun:
            log = fun(level=level, og_msg=log_msg, sandesh=self._sandesh)
            log.send(sandesh=self._sandesh)
        else:
            self._sandesh.logger().log(
                    SandeshLogger.get_py_logger_level(level), log_msg)

    def emergency(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_EMERG, fun=log_fun)

    def alert(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_ALERT, fun=log_fun)

    def critical(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_CRIT, fun=log_fun)

    def error(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_ERR, fun=log_fun)

    def cgitb_error(self):
        string_buf = cStringIO.StringIO()
        cgitb_hook(file=string_buf, format="text")
        self.error(string_buf.getvalue())

    def warning(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_WARN, fun=log_fun)

    def notice(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_NOTICE, fun=log_fun)

    def info(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_INFO, fun=log_fun)

    def debug(self, log_msg, log_fun=None):
        self.log(log_msg, level=SandeshLevel.SYS_DEBUG, fun=log_fun)

    def _utc_timestamp_usec(self):
        epoch = datetime.datetime.utcfromtimestamp(0)
        now = datetime.datetime.utcnow()
        delta = now - epoch
        return (delta.microseconds +
                (delta.seconds + delta.days * 24 * 3600) * 10 ** 6)

    def redefine_sandesh_handles(self):
        """ Redefine sandesh handle requests for various object types. """
        pass

    def sandesh_init(self, http_server_port=None):
        """ Init sandesh """
        self._sandesh = Sandesh()
        self.redefine_sandesh_handles()
        if not http_server_port:
            http_server_port = self._args.http_server_port
        self._sandesh.init_generator(
            self._module_name, self._hostname, self._node_type_name,
            self._instance_id, self._args.random_collectors,
            '%s_context' % self.context, int(http_server_port),
            ['cfgm_common', '%s.sandesh' % self.module_pkg],
            logger_class=self._args.logger_class,
            logger_config_file=self._args.logging_conf,
            config=self._args.sandesh_config)

        self._sandesh.set_logging_params(
#.........这里部分代码省略.........
开发者ID:Juniper,项目名称:contrail-controller,代码行数:103,代码来源:vnc_logger.py

示例5: SvcMonitor

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]
class SvcMonitor(object):

    """
    data + methods used/referred to by ssrc and arc greenlets
    """

    _KEYSPACE = 'svc_monitor_keyspace'
    _SVC_VM_CF = 'svc_vm_table'
    _SVC_SI_CF = 'svc_si_table'
    _SVC_CLEANUP_CF = 'svc_cleanup_table'

    def __init__(self, vnc_lib, args=None):
        self._args = args

        # api server and cassandra init
        self._vnc_lib = vnc_lib
        self._cassandra_init()

        # dictionary for nova
        self._nova = {}

        #initialize discovery client
        self._disc = None
        if self._args.disc_server_ip and self._args.disc_server_port:
            self._disc = client.DiscoveryClient(self._args.disc_server_ip,
                                                self._args.disc_server_port,
                                                client_type='Service Monitor')

        #sandesh init
        self._sandesh = Sandesh()
        sandesh.ServiceInstanceList.handle_request =\
            self.sandesh_si_handle_request
        self._sandesh.init_generator(
            ModuleNames[Module.SVC_MONITOR], socket.gethostname(),
            self._args.collectors, 'svc_monitor_context',
            int(self._args.http_server_port), ['cfgm_common', 'sandesh'],
            self._disc)
        self._sandesh.set_logging_params(enable_local_log=self._args.log_local,
                                         category=self._args.log_category,
                                         level=self._args.log_level,
                                         file=self._args.log_file)

        #create default analyzer template
        self._create_default_template('analyzer-template', 'analyzer',
                                      'analyzer')
        self._create_default_template('nat-template', 'nat-service',
                                      'firewall', 'in-network-nat')

        #create cpu_info object to send periodic updates
        sysinfo_req = False
        cpu_info = vnc_cpu_info.CpuInfo(
            Module.SVC_MONITOR, sysinfo_req, self._sandesh, 60)
        self._cpu_info = cpu_info

        # logging
        self._err_file = '/var/log/contrail/svc-monitor.err'
        self._tmp_file = '/var/log/contrail/svc-monitor.tmp'
        self._svc_err_logger = logging.getLogger('SvcErrLogger')
        self._svc_err_logger.setLevel(logging.ERROR)
        handler = logging.handlers.RotatingFileHandler(
            self._err_file, maxBytes=64*1024, backupCount=2)
        self._svc_err_logger.addHandler(handler)
    # end __init__

    # create service template
    def _create_default_template(self, st_name, image_name,
                                 svc_type, svc_mode=None):
        domain_name = 'default-domain'
        domain_fq_name = [domain_name]
        st_fq_name = [domain_name, st_name]
        self._svc_syslog("Creating %s %s image %s" %
                         (domain_name, st_name, image_name))

        try:
            st_obj = self._vnc_lib.service_template_read(fq_name=st_fq_name)
            st_uuid = st_obj.uuid
        except NoIdError:
            domain = self._vnc_lib.domain_read(fq_name=domain_fq_name)
            st_obj = ServiceTemplate(name=st_name, domain_obj=domain)
            st_uuid = self._vnc_lib.service_template_create(st_obj)

        svc_properties = ServiceTemplateType()
        svc_properties.set_image_name(image_name)
        svc_properties.set_service_type(svc_type)

        # set interface list
        if svc_type == 'analyzer':
            if_list = [['left', False]]
        else:
            if_list = [
                ['left', False], ['right', False], ['management', False]]
            svc_properties.set_service_mode(svc_mode)

        for itf in if_list:
            if_type = ServiceTemplateInterfaceType(shared_ip=itf[1])
            if_type.set_service_interface_type(itf[0])
            svc_properties.add_interface_type(if_type)

        try:
            st_obj.set_service_template_properties(svc_properties)
#.........这里部分代码省略.........
开发者ID:linbiyi,项目名称:contrail-controller,代码行数:103,代码来源:svc_monitor.py

示例6: MesosManagerLogger

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]

#.........这里部分代码省略.........

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # NOTICE.
    def notice(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_NOTICE
        logging_fun = log_fun if log_fun else sandesh.MesosManagerNoticeLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # INFO.
    def info(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_INFO
        logging_fun = log_fun if log_fun else sandesh.MesosManagerInfoLog

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # DEBUG.
    def debug(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_DEBUG
        logging_fun = log_fun if log_fun else sandesh.MesosManagerDebugLog

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    def redefine_sandesh_handles(self):
        """ Register custom introspect handlers. """

        # Register Virtual Machine DB introspect handler.
        introspect.VirtualMachineDatabaseList.handle_request = \
            VirtualMachineMM.sandesh_handle_db_list_request

        # Register Virtual Router DB introspect handler.
        introspect.VirtualRouterDatabaseList.handle_request = \
            VirtualRouterMM.sandesh_handle_db_list_request

        # Register Virtual Machine Interface DB introspect handler.
        introspect.VirtualMachineInterfaceDatabaseList.handle_request = \
            VirtualMachineInterfaceMM.sandesh_handle_db_list_request

        # Register Virtual Network DB introspect handler.
        introspect.VirtualNetworkDatabaseList.handle_request = \
            VirtualNetworkMM.sandesh_handle_db_list_request

        # Register Instance IP DB introspect handler.
        introspect.InstanceIpDatabaseList.handle_request = \
            InstanceIpMM.sandesh_handle_db_list_request

        # Register Project DB introspect handler.
        introspect.ProjectDatabaseList.handle_request = \
            ProjectMM.sandesh_handle_db_list_request

        # Register Domain DB introspect handler.
        introspect.DomainDatabaseList.handle_request = \
            DomainMM.sandesh_handle_db_list_request

        # Register NetworkIpam DB introspect handler.
        introspect.NetworkIpamDatabaseList.handle_request = \
            NetworkIpamMM.sandesh_handle_db_list_request

    def sandesh_init(self):
        """ Init Sandesh """
        self._sandesh = Sandesh()

        # Register custom sandesh request handlers.
        self.redefine_sandesh_handles()

        # Initialize Sandesh generator.
        self._sandesh.init_generator(
            self.module['name'], self.module['hostname'],
            self.module['node_type_name'], self.module['instance_id'],
            self._args.collectors, 'mesos_manager_context',
            int(self._args.http_server_port),
            ['cfgm_common', 'mesos_manager.sandesh', 'mesos_introspect.sandesh'],
            logger_class=self._args.logger_class,
            logger_config_file=self._args.logging_conf,
            config=self._args.sandesh_config)

        # Set Sandesh logging params.
        self._sandesh.set_logging_params(
            enable_local_log=self._args.log_local,
            category=self._args.log_category,
            level=self._args.log_level, file=self._args.log_file,
            enable_syslog=self._args.use_syslog,
            syslog_facility=self._args.syslog_facility)

        # Connect to collector.
        ConnectionState.init(self._sandesh, self.module['hostname'],
            self.module['name'], self.module['instance_id'],
            staticmethod(ConnectionState.get_conn_state_cb),
            NodeStatusUVE, NodeStatus, self.module['table'])

    def introspect_init(self):
        self._sandesh.run_introspect_server(int(self._args.http_server_port))
开发者ID:Juniper,项目名称:contrail-controller,代码行数:104,代码来源:logger.py

示例7: MesosManagerLogger

# 需要导入模块: from pysandesh.sandesh_base import Sandesh [as 别名]
# 或者: from pysandesh.sandesh_base.Sandesh import set_logging_params [as 别名]

#.........这里部分代码省略.........

    # ALERT.
    def alert(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_ALERT
        logging_fun = log_fun if log_fun else sandesh.MesosManagerAlertLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # CRITICAL.
    def critical(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_CRIT
        logging_fun = log_fun if log_fun else sandesh.MesosManagerCriticalLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # CRITICAL.
    def error(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_ERR
        logging_fun = log_fun if log_fun else sandesh.MesosManagerErrorLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # WARNING.
    def warning(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_WARN
        logging_fun = log_fun if log_fun else sandesh.MesosManagerWarningLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # NOTICE.
    def notice(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_NOTICE
        logging_fun = log_fun if log_fun else sandesh.MesosManagerNoticeLog

        # Log to syslog.
        self.syslog(log_msg, log_level)

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # INFO.
    def info(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_INFO
        logging_fun = log_fun if log_fun else sandesh.MesosManagerInfoLog

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    # DEBUG.
    def debug(self, log_msg, log_fun=None):
        log_level = SandeshLevel.SYS_DEBUG
        logging_fun = log_fun if log_fun else sandesh.MesosManagerDebugLog

        # Log using the desired logging function.
        self.log(log_msg, level=log_level, fun=logging_fun)

    def sandesh_init(self):
        """ Init Sandesh """
        self._sandesh = Sandesh()

        # Initialize Sandesh generator.
        self._sandesh.init_generator(
            self.module['name'], self.module['hostname'],
            self.module['node_type_name'], self.module['instance_id'],
            self._args.collectors, 'mesos_manager_context',
            int(self._args.http_server_port),
            ['cfgm_common', 'mesos_manager.sandesh'],
            logger_class=self._args.logger_class,
            logger_config_file=self._args.logging_conf,
            config=self._args.sandesh_config)

        # Set Sandesh logging params.
        self._sandesh.set_logging_params(
            enable_local_log=self._args.log_local,
            category=self._args.log_category,
            level=self._args.log_level, file=self._args.log_file,
            enable_syslog=self._args.use_syslog,
            syslog_facility=self._args.syslog_facility)

        # Connect to collector.
        ConnectionState.init(self._sandesh, self.module['hostname'],
            self.module['name'], self.module['instance_id'],
            staticmethod(ConnectionState.get_process_state_cb),
            NodeStatusUVE, NodeStatus, self.module['table'])
开发者ID:cijohnson,项目名称:contrail-controller,代码行数:104,代码来源:logger.py


注:本文中的pysandesh.sandesh_base.Sandesh.set_logging_params方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。