feat(playout): enhance playout logging (#1495)

Some initial work on modernizing the playout app. This replace any custom logger or
logging based logger with the logging tools from libretime_shared.logging and loguru.

Removed all the thread/function assigned logger (self.logger = ...), as this makes it
part of the logic (passing logger though function args) as it should not.

Of a dedicated logger is required for a specific task, it should use
the create_task_logger function.

- refactor: remove dead code
- refactor: remove py2 specific fix
- feat: remove unused test command
- feat: setup shared cli and logging tools
- feat: replace logging with loguru
- feat: setup shared cli and logging tools for notify
- fix: warn method deos not exist
- feat: make cli setup the entrypoint
- fix: install shared modules globally in production
  use extra_requires to load local packages in dev environement
- feat: configure log path in systemd service
- feat: default behavior is to log to console only
- feat: create log dir during install
- chore: add comment
- fix: don't create useless dir in install
- fix: move notify logs to /var/log/libretime dir
- fix: update setup_logger attrs
- style: linting
- fix: replace verbosity flag with log-level flag
- feat: use shared logging tool in liquidsoap
- fix: pass logger down to api client
- feat: allow custom log_filepath in liquidsoap config
- chore: add pylintrc to playout
- refactor: fix pylint errors
- feat: set liquidsoap log filepath in systemd service
- fix: missing setup entrypoint update

BREAKING CHANGE: for playout and liquidsoap the default log file path changed to None
and will only log to the console when developing / testing. Unless you are running the
app as a systemd service (production) the default logs filepaths changed:
from "/var/log/airtime/pypo/pypo.log" to "/var/log/libretime/playout.log" and
from "/var/log/airtime/pypo-liquidsoap/ls_script.log" to "/var/log/libretime/liquidsoap.log"

BREAKING CHANGE: for playout-notify the default log file path changed
from "/var/log/airtime/pypo/notify.log" to "/var/log/libretime/playout-notify.log"
This commit is contained in:
Jonas L 2022-01-13 16:11:37 +01:00 committed by GitHub
parent 56a3875e2d
commit 5c72f714a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 323 additions and 452 deletions

View file

@ -1,5 +1,4 @@
import json
import logging
import os
import sys
import time
@ -13,8 +12,7 @@ from kombu.connection import Connection
from kombu.messaging import Exchange, Queue
from kombu.mixins import ConsumerMixin
from kombu.simple import SimpleQueue
logging.captureWarnings(True)
from loguru import logger
class RabbitConsumer(ConsumerMixin):
@ -36,13 +34,12 @@ class RabbitConsumer(ConsumerMixin):
class PypoMessageHandler(Thread):
def __init__(self, pq, rq, config):
Thread.__init__(self)
self.logger = logging.getLogger("message_h")
self.pypo_queue = pq
self.recorder_queue = rq
self.config = config
def init_rabbit_mq(self):
self.logger.info("Initializing RabbitMQ stuff")
logger.info("Initializing RabbitMQ stuff")
try:
schedule_exchange = Exchange(
"airtime-pypo", "direct", durable=True, auto_delete=True
@ -58,7 +55,7 @@ class PypoMessageHandler(Thread):
rabbit = RabbitConsumer(connection, [schedule_queue], self)
rabbit.run()
except Exception as e:
self.logger.error(e)
logger.error(e)
"""
Handle a message from RabbitMQ, put it into our yucky global var.
@ -67,7 +64,7 @@ class PypoMessageHandler(Thread):
def handle_message(self, message):
try:
self.logger.info("Received event from RabbitMQ: %s" % message)
logger.info("Received event from RabbitMQ: %s" % message)
try:
message = message.decode()
@ -75,50 +72,48 @@ class PypoMessageHandler(Thread):
pass
m = json.loads(message)
command = m["event_type"]
self.logger.info("Handling command: " + command)
logger.info("Handling command: " + command)
if command == "update_schedule":
self.logger.info("Updating schedule...")
logger.info("Updating schedule...")
self.pypo_queue.put(message)
elif command == "reset_liquidsoap_bootstrap":
self.logger.info("Resetting bootstrap vars...")
logger.info("Resetting bootstrap vars...")
self.pypo_queue.put(message)
elif command == "update_stream_setting":
self.logger.info("Updating stream setting...")
logger.info("Updating stream setting...")
self.pypo_queue.put(message)
elif command == "update_stream_format":
self.logger.info("Updating stream format...")
logger.info("Updating stream format...")
self.pypo_queue.put(message)
elif command == "update_station_name":
self.logger.info("Updating station name...")
logger.info("Updating station name...")
self.pypo_queue.put(message)
elif command == "switch_source":
self.logger.info("switch_source command received...")
logger.info("switch_source command received...")
self.pypo_queue.put(message)
elif command == "update_transition_fade":
self.logger.info("Updating trasition fade...")
logger.info("Updating trasition fade...")
self.pypo_queue.put(message)
elif command == "disconnect_source":
self.logger.info("disconnect_source command received...")
logger.info("disconnect_source command received...")
self.pypo_queue.put(message)
elif command == "update_recorder_schedule":
self.recorder_queue.put(message)
elif command == "cancel_recording":
self.recorder_queue.put(message)
else:
self.logger.info("Unknown command: %s" % command)
logger.info("Unknown command: %s" % command)
except Exception as e:
self.logger.error("Exception in handling RabbitMQ message: %s", e)
logger.error("Exception in handling RabbitMQ message: %s", e)
def main(self):
try:
self.init_rabbit_mq()
except Exception as e:
self.logger.error("Exception: %s", e)
self.logger.error("traceback: %s", traceback.format_exc())
self.logger.error(
"Error connecting to RabbitMQ Server. Trying again in few seconds"
)
logger.error("Exception: %s", e)
logger.error("traceback: %s", traceback.format_exc())
logger.error("Error connecting to RabbitMQ Server. Trying again in few seconds")
time.sleep(5)
"""