added logging queue

This commit is contained in:
Malachy Byrne 2023-04-13 00:43:36 +01:00
parent f118e109c2
commit d060d8e711
Signed by: malmal200
GPG Key ID: EC21443030A655D9
2 changed files with 32 additions and 0 deletions

8
functions.py Normal file
View File

@ -0,0 +1,8 @@
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password")))
channel = connection.channel()
def log(data):
channel.basic_publish(exchange='', routing_key='log', body=data)

24
log.py Normal file
View File

@ -0,0 +1,24 @@
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials("user", "password")))
channel = connection.channel()
channel.queue_declare(queue='log')
def log(ch, method, properties, body):
try:
data = body.decode()
except UnicodeDecodeError:
data = body
print(data)
channel.basic_consume(queue='log', on_message_callback=log, auto_ack=True)
try:
print("Opening logs")
channel.start_consuming()
except KeyboardInterrupt:
channel.stop_consuming()
channel.close()
print("Closing logs")