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:
parent
56a3875e2d
commit
5c72f714a8
21 changed files with 323 additions and 452 deletions
|
@ -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/<script>.log"\n')
|
||||
if log_filepath is not None:
|
||||
fh.write(f'log_file = "{log_filepath.resolve()}"\n')
|
||||
fh.write('auth_path = "%s/liquidsoap_auth.py"\n' % auth_path)
|
||||
fh.close()
|
||||
|
||||
|
||||
def run():
|
||||
logging.basicConfig(format="%(message)s")
|
||||
def run(log_filepath: Optional[Path]):
|
||||
attempts = 0
|
||||
max_attempts = 10
|
||||
successful = False
|
||||
|
||||
while not successful:
|
||||
try:
|
||||
ac = AirtimeApiClient(logging.getLogger())
|
||||
ac = AirtimeApiClient(logger)
|
||||
ss = ac.get_stream_setting()
|
||||
generate_liquidsoap_config(ss)
|
||||
generate_liquidsoap_config(ss, log_filepath)
|
||||
successful = True
|
||||
except Exception as e:
|
||||
print("Unable to connect to the Airtime server.")
|
||||
logging.error(str(e))
|
||||
logging.error("traceback: %s", traceback.format_exc())
|
||||
logger.error(str(e))
|
||||
logger.error("traceback: %s", traceback.format_exc())
|
||||
if attempts == max_attempts:
|
||||
logging.error("giving up and exiting...")
|
||||
logger.error("giving up and exiting...")
|
||||
sys.exit(1)
|
||||
else:
|
||||
logging.info("Retrying in 3 seconds...")
|
||||
logger.info("Retrying in 3 seconds...")
|
||||
time.sleep(3)
|
||||
attempts += 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue