From 5c72f714a817504f56b60122611911fd4550f3b7 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Thu, 13 Jan 2022 16:11:37 +0100 Subject: [PATCH] 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" --- install | 11 ++ playout/.pylintrc | 4 + playout/Makefile | 2 +- .../logrotate/libretime-liquidsoap.conf | 2 +- .../systemd/libretime-liquidsoap.service | 2 + .../install/systemd/libretime-playout.service | 2 + .../generate_liquidsoap_cfg.py | 24 +-- playout/libretime_liquidsoap/main.py | 35 ++-- playout/libretime_playout/listenerstat.py | 33 +--- playout/libretime_playout/main.py | 153 ++++-------------- playout/libretime_playout/notify/main.py | 39 ++--- playout/libretime_playout/pypofetch.py | 112 ++++++------- playout/libretime_playout/pypofile.py | 42 +++-- playout/libretime_playout/pypoliqqueue.py | 14 +- playout/libretime_playout/pypoliquidsoap.py | 25 ++- .../libretime_playout/pypomessagehandler.py | 41 +++-- playout/libretime_playout/pypopush.py | 35 ++-- playout/libretime_playout/recorder.py | 83 +++++----- playout/libretime_playout/telnetliquidsoap.py | 84 +++++----- playout/libretime_playout/testpypoliqqueue.py | 22 +-- playout/setup.py | 10 +- 21 files changed, 323 insertions(+), 452 deletions(-) create mode 100644 playout/.pylintrc diff --git a/install b/install index 5bf51fbb8..d37f7bd41 100755 --- a/install +++ b/install @@ -93,6 +93,12 @@ skip_postgres=0 skip_rabbitmq=0 default_value="Y" +# +mkdir_and_chown() { + mkdir -p "$2" + chown -R "$1" "$2" +} + function verbose() { if [[ ${_v} -eq 1 ]]; then echo -e "$@" @@ -1027,12 +1033,17 @@ if [ ! -d /var/log/airtime ]; then verbose "\n * Creating /var/log/airtime" loudCmd "mkdir -p /var/log/airtime" + mkdir_and_chown "$web_user:$web_user" "/var/log/libretime" verbose "\n * Copying logrotate files..." loudCmd "cp ${AIRTIMEROOT}/legacy/build/airtime-php.logrotate /etc/logrotate.d/airtime-php" loudCmd "cp ${AIRTIMEROOT}/playout/install/logrotate/libretime-liquidsoap.conf /etc/logrotate.d/libretime-liquidsoap" fi +verbose "\n * Installing Shared..." +loudCmd "$pip_cmd install ${AIRTIMEROOT}/shared" +verbose "...Done" + verbose "\n * Installing API client..." loudCmd "$pip_cmd install ${AIRTIMEROOT}/api_client" verbose "...Done" diff --git a/playout/.pylintrc b/playout/.pylintrc new file mode 100644 index 000000000..b2256f54f --- /dev/null +++ b/playout/.pylintrc @@ -0,0 +1,4 @@ +[MESSAGES CONTROL] +disable=missing-module-docstring, + missing-class-docstring, + missing-function-docstring, diff --git a/playout/Makefile b/playout/Makefile index d01412927..b713ae99e 100644 --- a/playout/Makefile +++ b/playout/Makefile @@ -2,7 +2,7 @@ all: lint include ../tools/python.mk -PIP_INSTALL := --editable . +PIP_INSTALL := --editable .[dev] PYLINT_ARG := libretime_liquidsoap libretime_playout MYPY_ARG := libretime_liquidsoap libretime_playout diff --git a/playout/install/logrotate/libretime-liquidsoap.conf b/playout/install/logrotate/libretime-liquidsoap.conf index 620a818cb..3e3f75f3e 100644 --- a/playout/install/logrotate/libretime-liquidsoap.conf +++ b/playout/install/logrotate/libretime-liquidsoap.conf @@ -1,4 +1,4 @@ -/var/log/airtime/pypo-liquidsoap/ls_script.log { +/var/log/libretime/liquidsoap.log { compress rotate 10 size 1000k diff --git a/playout/install/systemd/libretime-liquidsoap.service b/playout/install/systemd/libretime-liquidsoap.service index fc34cbec9..a266184d6 100644 --- a/playout/install/systemd/libretime-liquidsoap.service +++ b/playout/install/systemd/libretime-liquidsoap.service @@ -2,6 +2,8 @@ Description=Libretime Liquidsoap Service [Service] +Environment=LIBRETIME_LOG_FILEPATH=/var/log/libretime/liquidsoap.log + ExecStart=/usr/local/bin/libretime-liquidsoap User=libretime-playout Group=libretime-playout diff --git a/playout/install/systemd/libretime-playout.service b/playout/install/systemd/libretime-playout.service index 50b080ec4..a40b64268 100644 --- a/playout/install/systemd/libretime-playout.service +++ b/playout/install/systemd/libretime-playout.service @@ -3,6 +3,8 @@ Description=Libretime Playout Service After=network-online.target [Service] +Environment=LIBRETIME_LOG_FILEPATH=/var/log/libretime/playout.log + ExecStart=/usr/local/bin/libretime-playout User=libretime-pypo Group=libretime-pypo diff --git a/playout/libretime_liquidsoap/generate_liquidsoap_cfg.py b/playout/libretime_liquidsoap/generate_liquidsoap_cfg.py index a41e24c38..0c2694382 100644 --- a/playout/libretime_liquidsoap/generate_liquidsoap_cfg.py +++ b/playout/libretime_liquidsoap/generate_liquidsoap_cfg.py @@ -1,13 +1,15 @@ -import logging import os import sys import time import traceback +from pathlib import Path +from typing import Optional from libretime_api_client.version1 import AirtimeApiClient +from loguru import logger -def generate_liquidsoap_config(ss): +def generate_liquidsoap_config(ss, log_filepath: Optional[Path]): data = ss["msg"] fh = open("/etc/airtime/liquidsoap.cfg", "w") fh.write("################################################\n") @@ -34,31 +36,31 @@ def generate_liquidsoap_config(ss): fh.write("ignore(%s)\n" % key) auth_path = os.path.dirname(os.path.realpath(__file__)) - fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/