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


Python SysLogHandler.LOG_USER属性代码示例

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


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

示例1: __init__

# 需要导入模块: from logging.handlers import SysLogHandler [as 别名]
# 或者: from logging.handlers.SysLogHandler import LOG_USER [as 别名]
def __init__(self, app, address=('localhost', SYSLOG_UDP_PORT), facility=SysLogHandler.LOG_USER, socktype=SOCK_DGRAM, level=WARNING, format=None):
        """
        Initiate the instance
        :param app:             The application
        :type  app:             Application
        :param address:         The address
        :type  address:         tuple|str
        :param facility:        The facility to log
        :type  facility:        int
        :param socktype:        The socktype to log
        :type  socktype:        int
        :param level:           The minimum level to log
        :type  level:           int
        :param format:          The format for the formatter
        :type  format:          str
        """

        super(SysLog, self).__init__(address=address, facility=facility, socktype=socktype)

        self.setLevel(level)

        if format is None:
            format = '[%(asctime)s] %(levelname)-8s: %(message)s [in %(pathname)s:%(lineno)d]'
        self.setFormatter(Formatter(format)) 
开发者ID:LowieHuyghe,项目名称:edmunds,代码行数:26,代码来源:syslog.py

示例2: logsetup

# 需要导入模块: from logging.handlers import SysLogHandler [as 别名]
# 或者: from logging.handlers.SysLogHandler import LOG_USER [as 别名]
def logsetup(app):

    global _setup_done
    if _setup_done:
        return
    _setup_done = True

    logging.setLoggerClass(ContextAwareLogger)

    syslog_path = '/dev/log'
    if sys.platform == 'darwin':
        syslog_path = '/var/run/syslog'

    # Install log file handler
    handler = SysLogHandler(address=syslog_path, facility=SysLogHandler.LOG_USER)
    handler.name = "serverlog"
    handler.setFormatter(ServerLogFormatter())
    logging.root.addHandler(handler)

    # Install eventLog file handler
    handler = SysLogHandler(address=syslog_path, facility=SysLogHandler.LOG_LOCAL0)
    handler.name = "eventlog"
    handler.setFormatter(EventLogFormatter())
    l = logging.getLogger("eventlog")
    l.propagate = False
    l.addHandler(handler)

    # Install client file handler
    handler = SysLogHandler(address=syslog_path, facility=SysLogHandler.LOG_LOCAL1)
    handler.name = "clientlog"
    handler.setFormatter(ClientLogFormatter())
    l = logging.getLogger("clientlog")
    l.propagate = False
    l.addHandler(handler)

    # Quiet down copule of very chatty loggers. This can be overridden in config.json.
    for logger_name in ['sqlalchemy', 'werkzeug', 'requests.packages.urllib3.connectionpool']:
        logging.getLogger(logger_name).setLevel('WARNING')

    # Apply additional 'level' and 'propagate' settings for handlers and
    # loggers. See https://docs.python.org/2.7/library/logging.config.html#
    # Example format:
    # "logging": {
    #     "version": 1,
    #     "incremental": true,
    #     "loggers": {
    #         "my_chatty_logger": {
    #             "level": "WARNING"
    #         }
    #     },
    #     "handlers": {
    #         "serverlog": {
    #             "level": "INFO",
    #         }
    #     }
    # }
    if 'logging' in app.config:
        logging.config.dictConfig(app.config['logging']) 
开发者ID:dgnorth,项目名称:drift,代码行数:60,代码来源:logging.py

示例3: setup_logger

# 需要导入模块: from logging.handlers import SysLogHandler [as 别名]
# 或者: from logging.handlers.SysLogHandler import LOG_USER [as 别名]
def setup_logger(self, session):
        """Setup logger for each device.

        Args:
            session(pytest.Session): pytest session

        """
        servers = []
        self.loggers = []  # pylint: disable=attribute-defined-outside-init
        self.logs_path = []  # pylint: disable=attribute-defined-outside-init

        switches_ids = session.config.env.switch
        for switch_id in switches_ids:
            switch = session.config.env.switch[switch_id]
            if "related_conf" in switch.config:
                for item in switch.config["related_conf"]:
                    if "instance_type" in switch.config["related_conf"][item]:
                        if switch.config["related_conf"][item]["instance_type"] == "syslog_settings":
                            path_to_log = switch.config["related_conf"][item]["path_to_log"]
                            switch_name = switch.config['name']
                            self.logs_path += [{switch_id: path_to_log}]
                            syslogserver_port = 514
                            syslogserver = switch.config["related_conf"][item]["ip"]
                            if "port" in switch.config["related_conf"][item]:
                                syslogserver_port = switch.config["related_conf"][item]["port"]
                            switch_item = {}
                            switch_item["ip"] = syslogserver
                            switch_item["name"] = switch_name
                            switch_item["port"] = syslogserver_port
                            servers.append(switch_item)

        for server in servers:
            syslogserver = server["ip"]
            syslogserver_port = server["port"]
            switch_name = server["name"]
            logger = logging.getLogger()
            formatter = logging.Formatter('%(module)s: %(levelname)s %(message)s')
            if sys.version_info >= (2, 7):
                syslog = SysLogHandler(address=(syslogserver, syslogserver_port),
                                       facility=SysLogHandler.LOG_USER,
                                       socktype=socket.SOCK_DGRAM)
            else:
                syslog = SysLogHandler(address=(syslogserver, syslogserver_port),
                                       facility=SysLogHandler.LOG_USER, )
            syslog.setFormatter(formatter)
            logger.addHandler(syslog)
            logger.setLevel(logging.INFO)
            logger_item = {}
            logger_item["name"] = switch_name
            logger_item["logger"] = logger
            self.loggers += [logger_item]

        self.setup_fail = False  # pylint: disable=attribute-defined-outside-init
        self.call_fail = False  # pylint: disable=attribute-defined-outside-init
        self.teardown_fail = False  # pylint: disable=attribute-defined-outside-init 
开发者ID:taf3,项目名称:taf,代码行数:57,代码来源:pytest_syslog.py


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