【问题标题】:ActiveMQ message bus logging handler pythonActiveMQ 消息总线日志记录处理程序 python
【发布时间】:2016-09-20 17:27:39
【问题描述】:

我想在LOG.debugLOG.info 时向ActiveMQ 发布消息,

我必须将处理程序添加到logging

如果有其他pythonic方法可以做到这一点?

【问题讨论】:

    标签: python logging activemq message-bus


    【解决方案1】:

    我创建了新的句柄来处理这个

    import json
    import logging
    
    from stompest.config import StompConfig
    from stompest.sync import Stomp
    
    class Handler(logging.Handler):
        def __init__(self, amq_uri, out_queue):
            logging.Handler.__init__(self)
            self.queue = queue
            self.uri = uri
    
        def emit(self, record):
            msg = self.format(record)
            cfg = StompConfig(self.uri)
            data = json.dumps(msg)
            client = Stomp(cfg)
            client.connect()
    
            try:
                client.send(self.queue, data)
            except Exception, exc:
                print "Error: ", exc
            client.disconnect()
    
    def get_logger(uri, queue):
        logger = logging.getLogger('testlogger')
        logger.addHandler(Handler(uri, queue))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 2023-01-10
      • 2015-05-03
      相关资源
      最近更新 更多