代码拉取完成,页面将自动刷新
同步操作将从 好雨科技/rainbond-console 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import time
import socket
import logging
import zmq
from zmq.log.handlers import PUBHandler
from zmq.utils.strtypes import cast_bytes
TOPIC_DELIM = " :: "
HOSTNAME = socket.gethostname()
class MyLogRecord(logging.LogRecord):
def __init__(self, name, level, pathname, lineno, msg, args, exc_info, func=None):
if args and '%' not in msg:
arg = args[0]
try:
msg = '{0}{1}{2}'.format(msg, TOPIC_DELIM, arg)
except Exception:
print("type is %s" % type(arg))
print("arg is", arg)
finally:
args = []
super(MyLogRecord, self).__init__(name, level, pathname, lineno, msg, args, exc_info, func=func)
logging.LogRecord = MyLogRecord
class ZmqHandler(PUBHandler):
def __init__(self, address, root_topic):
logging.Handler.__init__(self)
self.ctx = zmq.Context()
self.socket = None
if '.' in root_topic:
raise AttributeError("root_topic should not contains any '.', provided '%s'" % root_topic)
self.root_topic = root_topic
self.zmq_address = address
def is_connected(self):
return bool(self.socket is not None)
def connect(self):
self.socket = self.ctx.socket(zmq.PUB)
self.socket.connect(self.zmq_address)
def format(self, record):
fmt = self.formatter
return fmt.format(record)
def emit(self, record):
"""Emit a log message on my socket."""
try:
topic, record.msg = record.msg.split(TOPIC_DELIM, 1)
except Exception:
topic = "untopic"
record.__dict__['hostname'] = HOSTNAME
try:
bmsg = cast_bytes(self.format(record))
except Exception:
self.handleError(record)
return
topic_list = [self.root_topic, topic]
btopic = b'.'.join(cast_bytes(t) for t in topic_list)
blevel = cast_bytes(record.levelname)
if not self.is_connected():
self.connect()
time.sleep(0.1)
self.socket.send_multipart([btopic, blevel, bmsg])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。