本文整理匯總了Python中zmq.log.handlers.PUBHandler類的典型用法代碼示例。如果您正苦於以下問題:Python PUBHandler類的具體用法?Python PUBHandler怎麽用?Python PUBHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了PUBHandler類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
def __init__(self, interface_or_socket, context=None):
PUBHandler.__init__(self, interface_or_socket, context)
self.formatters = {
logging.DEBUG: logging.Formatter("%(asctime)-6s: %(name)s - %(levelname)s %(filename)s:%(lineno)d - %(message)s\n"),
logging.INFO: logging.Formatter("%(asctime)-6s: %(name)s - %(message)s\n"),
logging.WARN: logging.Formatter("%(asctime)-6s: %(name)s - %(levelname)s %(filename)s:%(lineno)d - %(message)s\n"),
logging.ERROR: logging.Formatter("%(asctime)-6s: %(name)s - %(levelname)s %(filename)s:%(lineno)d - %(message)s - %(exc_info)s\n"),
logging.CRITICAL: logging.Formatter("%(asctime)-6s: %(name)s - %(levelname)s %(filename)s:%(lineno)d - %(message)s\n")}
示例2: forward_logging
def forward_logging(self):
if self.log_url:
self.log.info("Forwarding logging to %s"%self.log_url)
context = zmq.Context.instance()
lsock = context.socket(zmq.PUB)
lsock.connect(self.log_url)
handler = PUBHandler(lsock)
handler.root_topic = 'controller'
handler.setLevel(self.log_level)
self.log.addHandler(handler)
示例3: start_logging
def start_logging(self):
super(IPControllerApp, self).start_logging()
if self.master_config.Global.log_url:
context = self.factory.context
lsock = context.socket(zmq.PUB)
lsock.connect(self.master_config.Global.log_url)
handler = PUBHandler(lsock)
handler.root_topic = 'controller'
handler.setLevel(self.log_level)
self.log.addHandler(handler)
示例4: zmq_external_logger
def zmq_external_logger(host='localhost', port='8899'):
'''
This publish logging messages over a zmq.PUB socket
'''
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.connect('tcp://{0}:{1}'.format(host, port))
handler = PUBHandler(socket)
logger = logging.getLogger()
logger.addHandler(handler)
handler.root_topic = 'logging'
return logger
示例5: run
def run(self):
context = zmq.Context()
pub = context.socket(zmq.PUB)
pub.connect(self.add_log)
self.log = logging.getLogger()
self.log.setLevel(logging.DEBUG)
handler = PUBHandler(pub)
handler.formatters = formatters
self.log.addHandler(handler)
self.log.debug('start_sink')
self.receiver = context.socket(zmq.PULL)
self.receiver.bind(self.add_rec)
self.controller = context.socket(zmq.PUB)
self.controller.bind(self.add_pub)
#socket to sinks
self.main = context.socket(zmq.PUSH)
self.main.connect(self.add_push)
# Message from main: start
self.receiver.recv()
#Measure time!
t_start = time.time()
results = []
for task_nbr in range(self.tasks):
raw_json_data = self.receiver.recv()
res = json.loads(
raw_json_data,
object_hook=MyOptResult.unserialize_object
)
results.append(res)
t_end = time.time()
t_duration = t_end - t_start
self.log.debug(
'Collected {count} results'.format(
count=len(results),
)
)
self.log.debug(
'Total elapsed time: {duration} s'.format(duration=t_duration)
)
self.controller.send(b'KILL')
self.handle_results(results)
time.sleep(1)
self.main.send(b'0')
示例6: PublishLogging
def PublishLogging(self,LoggingName="zmq.auth", root_topic="zmq.auth"):
"""
Publishes the given python logger to the publishing service
:param LoggingName: Name of the python logger service
:type LoggingName: str
:param root_topic: the topic given with message. is appended with .<LEVEL>
:type root_topic: str
:return:
"""
handler = PUBHandler(self.Logger)
handler.root_topic = root_topic
handler.formatters[logging.DEBUG] = logging.Formatter(fmt='%(asctime)s\t%(levelname)s: %(message)s', datefmt='%H:%M:%S')
handler.formatters[logging.INFO] = logging.Formatter(fmt='%(asctime)s\t%(levelname)s: %(message)s', datefmt='%H:%M:%S')
l = logging.getLogger(LoggingName)
l.addHandler(handler)
示例7: _start_logger
def _start_logger(context):
global log
controller = context.socket(zmq.PUB)
controller.bind(ADD_LOG_CONTROLLER)
l = Logger(ADD_LOGGING, ADD_LOG_LH_CONTROLLER)
l.start()
time.sleep(2)
pub = context.socket(zmq.PUB)
pub.connect(ADD_LH_LOGGING)
log = logging.getLogger('main')
log.setLevel(logging.DEBUG)
handler = PUBHandler(pub)
handler.formatters = formatters
log.addHandler(handler)
return controller
示例8: __init__
def __init__(self, engine, *args, **kwargs):
PUBHandler.__init__(self,*args, **kwargs)
self.engine = engine
示例9: register_zmq_handler
def register_zmq_handler(cls, zmq_socket): # pragma: no cover
handler = PUBHandler(zmq_socket)
handler.root_topic = "logger"
logger = logging.getLogger()
logger.addHandler(handler)
示例10: main
def main(settings):
"""
The :meth:`main` method for worker processes.
Here we will:
- create a :class:`ZmqMgmt` instance
- create a :class:`Fetcher` instance
- initialize and instantiate the extractor chain
The `settings` have to be loaded already.
"""
# create my own identity
identity = "worker:%s:%s" % (socket.gethostname(), os.getpid())
ctx = zmq.Context()
io_loop = IOLoop.instance()
# initialize the logging subsystem
log_pub = ctx.socket(zmq.PUB)
log_pub.connect(settings.ZEROMQ_LOGGING)
zmq_logging_handler = PUBHandler(log_pub)
zmq_logging_handler.root_topic = "spyder.worker"
logger = logging.getLogger()
logger.addHandler(zmq_logging_handler)
logger.setLevel(settings.LOG_LEVEL_WORKER)
logger.info("process::Starting up another worker")
mgmt = create_worker_management(settings, ctx, io_loop)
logger.debug("process::Initializing fetcher, extractor and scoper")
fetcher = create_worker_fetcher(settings, mgmt, ctx, zmq_logging_handler,
io_loop)
fetcher.start()
extractor = create_worker_extractor(settings, mgmt, ctx,
zmq_logging_handler, io_loop)
extractor.start()
def quit_worker(raw_msg):
"""
When the worker should quit, stop the io_loop after 2 seconds.
"""
msg = MgmtMessage(raw_msg)
if ZMQ_SPYDER_MGMT_WORKER_QUIT == msg.data:
logger.info("process::We have been asked to shutdown, do so")
DelayedCallback(io_loop.stop, 2000, io_loop).start()
ack = MgmtMessage(topic=ZMQ_SPYDER_MGMT_WORKER, identity=identity,
data=ZMQ_SPYDER_MGMT_WORKER_QUIT_ACK)
mgmt._out_stream.send_multipart(ack.serialize())
mgmt.add_callback(ZMQ_SPYDER_MGMT_WORKER, quit_worker)
mgmt.start()
# notify the master that we are online
msg = MgmtMessage(topic=ZMQ_SPYDER_MGMT_WORKER, identity=identity,
data=ZMQ_SPYDER_MGMT_WORKER_AVAIL)
mgmt._out_stream.send_multipart(msg.serialize())
def handle_shutdown_signal(_sig, _frame):
"""
Called from the os when a shutdown signal is fired.
"""
msg = MgmtMessage(data=ZMQ_SPYDER_MGMT_WORKER_QUIT)
quit_worker(msg.serialize())
# zmq 2.1 stops blocking calls, restart the ioloop
io_loop.start()
# handle kill signals
signal.signal(signal.SIGINT, handle_shutdown_signal)
signal.signal(signal.SIGTERM, handle_shutdown_signal)
logger.info("process::waiting for action")
# this will block until the worker quits
try:
io_loop.start()
except ZMQError:
logger.debug("Caught a ZMQError. Hopefully during shutdown")
logger.debug(traceback.format_exc())
for mod in [fetcher, extractor, mgmt]:
mod.close()
logger.info("process::Houston: Worker down")
ctx.term()
示例11: main
def main(settings):
"""
Main method for master processes.
"""
# create my own identity
identity = "master:%s:%s" % (socket.gethostname(), os.getpid())
ctx = zmq.Context()
io_loop = IOLoop.instance()
# initialize the logging subsystem
log_pub = ctx.socket(zmq.PUB)
log_pub.connect(settings.ZEROMQ_LOGGING)
zmq_logging_handler = PUBHandler(log_pub)
zmq_logging_handler.root_topic = "spyder.master"
logger = logging.getLogger()
logger.addHandler(zmq_logging_handler)
logger.setLevel(settings.LOG_LEVEL_MASTER)
logger.info("process::Starting up the master")
mgmt = create_master_management(settings, ctx, io_loop)
frontier = create_frontier(settings, zmq_logging_handler)
publishing_socket = ctx.socket(zmq.PUSH)
publishing_socket.setsockopt(zmq.HWM, settings.ZEROMQ_MASTER_PUSH_HWM)
publishing_socket.bind(settings.ZEROMQ_MASTER_PUSH)
receiving_socket = ctx.socket(zmq.SUB)
receiving_socket.setsockopt(zmq.SUBSCRIBE, "")
receiving_socket.bind(settings.ZEROMQ_MASTER_SUB)
master = ZmqMaster(settings, identity, receiving_socket,
publishing_socket, mgmt, frontier, zmq_logging_handler,
settings.LOG_LEVEL_MASTER, io_loop)
def handle_shutdown_signal(_sig, _frame):
"""
Called from the os when a shutdown signal is fired.
"""
master.shutdown()
# zmq 2.1 stops blocking calls, restart the ioloop
io_loop.start()
# handle kill signals
signal.signal(signal.SIGINT, handle_shutdown_signal)
signal.signal(signal.SIGTERM, handle_shutdown_signal)
if settings.MASTER_CALLBACK:
callback = import_class(settings.MASTER_CALLBACK)
callback(settings, ctx, io_loop, frontier)
mgmt.start()
master.start()
# this will block until the master stops
try:
io_loop.start()
except ZMQError:
logger.debug("Caught a ZMQError. Hopefully during shutdown")
logger.debug(traceback.format_exc())
master.close()
mgmt.close()
logger.info("process::Master is down.")
log_pub.close()
ctx.term()