本文整理汇总了Python中logging.Handler方法的典型用法代码示例。如果您正苦于以下问题:Python logging.Handler方法的具体用法?Python logging.Handler怎么用?Python logging.Handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.Handler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, host, port):
"""
Initializes the handler with a specific host address and port.
When the attribute *closeOnError* is set to True - if a socket error
occurs, the socket is silently closed and then reopened on the next
logging call.
"""
logging.Handler.__init__(self)
self.host = host
self.port = port
self.sock = None
self.closeOnError = False
self.retryTime = None
#
# Exponential backoff parameters.
#
self.retryStart = 1.0
self.retryMax = 30.0
self.retryFactor = 2.0
示例2: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, host, port):
"""
Initializes the handler with a specific host address and port.
The attribute 'closeOnError' is set to 1 - which means that if
a socket error occurs, the socket is silently closed and then
reopened on the next logging call.
"""
logging.Handler.__init__(self)
self.host = host
self.port = port
self.sock = None
self.closeOnError = 0
self.retryTime = None
#
# Exponential backoff parameters.
#
self.retryStart = 1.0
self.retryMax = 30.0
self.retryFactor = 2.0
示例3: set_formatter
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def set_formatter(self, handler_id, formatter):
"""Set the formatter of the specified handler.
Parameters
----------
handler_id : unicode
Id of the handler whose formatter shoudl be set.
formatter : Formatter
Formatter for the handler.
"""
handlers = self._handlers
handler_id = str(handler_id)
if handler_id in handlers:
handler, _ = handlers[handler_id]
handler.setFormatter(formatter)
else:
logger = logging.getLogger(__name__)
logger.warning('Handler {} does not exist')
# ---- Private API --------------------------------------------------------
# Mapping between handler ids and handler, logger name pairs.
示例4: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, topic_arn):
logging.Handler.__init__(self)
self.client = boto3.client("sns")
self.topic_arn = topic_arn
示例5: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, distutils_log=log):
logging.Handler.__init__(self)
self.log = distutils_log
# Basic numeric table
self.level_table = {
logging.CRITICAL: distutils_log.FATAL,
logging.ERROR: distutils_log.ERROR,
logging.WARNING: distutils_log.WARN,
logging.INFO: distutils_log.INFO,
logging.DEBUG: distutils_log.DEBUG,
}
self.setFormatter(logging.Formatter('%(message)s'))
示例6: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, db):
"""
Constructor
@param db: ['host','port','dbuser', 'dbpassword', 'dbname']
@return: mySQLHandler
"""
logging.Handler.__init__(self)
self.db = db
# Try to connect to DB
# Check if 'log' table in db already exists
result = self.checkTablePresence()
# If not exists, then create the table
if not result:
try:
conn=MySQLdb.connect(host=self.db['host'],port=self.db['port'],user=self.db['dbuser'],passwd=self.db['dbpassword'],db=self.db['dbname'])
except _mysql_exceptions, e:
raise Exception(e)
exit(-1)
else:
cur = conn.cursor()
try:
cur.execute(mySQLHandler.initial_sql)
except _mysql_exceptions as e:
conn.rollback()
cur.close()
conn.close()
raise Exception(e)
exit(-1)
else:
conn.commit()
finally:
cur.close()
conn.close()
示例7: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, uri):
logging.Handler.__init__(self)
RelationalMixin.__init__(self, uri)
示例8: handleError
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def handleError(self, record):
"""
Handle an error during logging.
An error has occurred during logging. Most likely cause -
connection lost. Close the socket so that we can retry on the
next event.
"""
if self.closeOnError and self.sock:
self.sock.close()
self.sock = None #try to reconnect next time
else:
logging.Handler.handleError(self, record)
示例9: close
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def close(self):
"""
Closes the socket.
"""
self.acquire()
try:
if self.sock:
self.sock.close()
self.sock = None
logging.Handler.close(self)
finally:
self.release()
示例10: to_berny_log
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def to_berny_log(pyscf_log):
'''Adapter to allow pyberny to use pyscf.logger
'''
class PyscfHandler(logging.Handler):
def emit(self, record):
pyscf_log.info(record.getMessage())
log = logging.getLogger('{}.{}'.format(__name__, id(pyscf_log)))
log.addHandler(PyscfHandler())
log.setLevel('INFO')
return log
示例11: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, errprinter):
logging.Handler.__init__(self)
self.errprinter = errprinter
示例12: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, saveto=None, *args, **kwargs):
self.saveto = saveto
logging.Handler.__init__(self, *args, **kwargs)
示例13: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def __init__(self, *args, **kwargs):
self.queries = []
logging.Handler.__init__(self, *args, **kwargs)
示例14: pytest_sessionstart
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def pytest_sessionstart(self, session):
handler = Handler()
logging.root.addHandler(handler)
yield
示例15: test_good_config_file
# 需要导入模块: import logging [as 别名]
# 或者: from logging import Handler [as 别名]
def test_good_config_file(tmp_path):
cfg = get_config_from_file(tmp_path, GOOD_CONFIG)
# Pass config to EventLog
e = EventLog(config=cfg)
# Assert the
assert len(e.handlers) > 0
assert isinstance(e.handlers[0], logging.Handler)