def main(config_file, **kwargs): with open(config_file) as fh: config = yaml.load(fh) try: rmq_settings = config["rabbitmq_logging"] except KeyError: print("RabbitMQ logging not configured in {}".format(config_file)) sys.exit() handlers = [NullHandler()] if not kwargs["quiet"]: handlers.append(StderrHandler(bubble=True)) if kwargs["filename"]: handlers.append(FileHandler(kwargs["filename"], bubble=True)) if kwargs["log_db"]: try: cdb_settings = config["couchdb_logging"] except KeyError: print("CouchDB logging not configured in {}".format(config_file)) sys.exit() db_handler = DatabaseHandler(cdb_settings["couchdb_url"], backend=CouchDBBackend, db=cdb_settings["database"], bubble=True) handlers.append(db_handler) setup = NestedSetup(handlers) print("Now waiting for log messages") with setup: subscriber = RabbitMQSubscriber(rmq_settings["url"], queue=rmq_settings["log_queue"]) try: subscriber.dispatch_forever() except KeyboardInterrupt: print("\nLog subscriber shutting down") subscriber.close() except Exception: print("Log subscriber quit (unexpectedly)")
from logbook.queues import RabbitMQSubscriber from logbook import StderrHandler std_handler = StderrHandler() with std_handler: subscriber = RabbitMQSubscriber('amqp://*****:*****@localhost//') subscriber.dispatch_forever()