本文整理汇总了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))
示例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'])
示例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