當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。