本文整理汇总了Python中freenas.dispatcher.client.Client.call_async方法的典型用法代码示例。如果您正苦于以下问题:Python Client.call_async方法的具体用法?Python Client.call_async怎么用?Python Client.call_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freenas.dispatcher.client.Client
的用法示例。
在下文中一共展示了Client.call_async方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LogdLogHandler
# 需要导入模块: from freenas.dispatcher.client import Client [as 别名]
# 或者: from freenas.dispatcher.client.Client import call_async [as 别名]
class LogdLogHandler(logging.Handler):
def __init__(self, level=logging.NOTSET, address=None, ident=None):
super(LogdLogHandler, self).__init__(level)
self.address = address or 'unix:///var/run/logd.sock'
self.ident = ident or os.path.basename(sys.executable)
self.client = Client()
self.client.connect(self.address)
def emit(self, record):
try:
if not self.client.connected:
self.client.connect(self.address)
item = {
'timestamp': datetime.utcfromtimestamp(record.created),
'priority': PRIORITY_MAP.get(record.levelno, 'INFO'),
'message': record.getMessage(),
'identifier': self.ident,
'thread': record.threadName,
'tid': record.thread,
'module_name': record.name,
'source_language': 'python',
'source_file': record.pathname,
'source_line': record.lineno,
}
if record.exc_info:
item['exception'] = ''.join(traceback.format_exception(*record.exc_info))
self.client.call_async('logd.logging.push', None, item)
except:
self.handleError(record)
def close(self):
super(LogdLogHandler, self).close()
self.client.disconnect()