From 50c7a5ca61567671c87ac8f5dbf078852185acbd Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 23 Apr 2020 15:41:46 +0200 Subject: [PATCH] fix debug vari --- larigira/event.py | 19 ++++++++++++------- larigira/larigira.py | 40 +++++++++++++++++++++++++++++----------- larigira/mpc.py | 4 +++- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/larigira/event.py b/larigira/event.py index f8141fc..70ea88c 100644 --- a/larigira/event.py +++ b/larigira/event.py @@ -1,17 +1,20 @@ from __future__ import print_function -from gevent import monkey -monkey.patch_all(subprocess=True) import logging from datetime import datetime, timedelta import gevent +from gevent import monkey from gevent.queue import Queue -from .eventutils import ParentedLet, Timer -from .timegen import timegenerate from .audiogen import audiogenerate from .db import EventModel +from .eventutils import ParentedLet, Timer +from .timegen import timegenerate + +monkey.patch_all(subprocess=True) + + logging.getLogger("mpd").setLevel(logging.WARNING) @@ -75,9 +78,11 @@ class Monitor(ParentedLet): # but it is "tricky"; any small delay would cause the event to be # missed if delta is None: - self.log.debug( - "Skipping event %s: will never ring", alarm.get("nick", alarm.eid) - ) + # this is way too much logging! we need more levels! + # self.log.debug( + # "Skipping event %s: will never ring", alarm.get("nick", alarm.eid) + # ) + pass elif delta <= 2 * self.conf["EVENT_TICK_SECS"]: self.log.debug( "Scheduling event %s (%ds) => %s", diff --git a/larigira/larigira.py b/larigira/larigira.py index c3d2a59..97c187d 100644 --- a/larigira/larigira.py +++ b/larigira/larigira.py @@ -2,34 +2,37 @@ This module is for the main application logic """ from __future__ import print_function -from gevent import monkey -monkey.patch_all(subprocess=True) - -import sys -import os -import tempfile -import signal -from time import sleep import logging import logging.config +import os +import signal import subprocess +import sys +import tempfile +from time import sleep import gevent +from gevent import monkey from gevent.pywsgi import WSGIServer -from .mpc import Controller, get_mpd_client from .config import get_conf +from .mpc import Controller, get_mpd_client from .rpc import create_app +monkey.patch_all(subprocess=True) + def on_main_crash(*args, **kwargs): print('A crash occurred in "main" greenlet. Aborting...') sys.exit(1) + + class Larigira(object): def __init__(self): + self.log = logging.getLogger("larigira") self.conf = get_conf() self.controller = Controller(self.conf) @@ -62,6 +65,7 @@ def main(): ) if not os.path.isdir(os.environ["TMPDIR"]): os.makedirs(os.environ["TMPDIR"]) + if get_conf()["LOG_CONFIG"]: logging.config.fileConfig( get_conf()["LOG_CONFIG"], disable_existing_loggers=True @@ -73,12 +77,26 @@ def main(): format=log_format, datefmt="%H:%M:%S", ) + logging.addLevelName(9, "DEBUGV") + + def debugv(self, message, *args, **kws): + if self.isEnabledFor(9): + self._log(9, message, args, **kws) + + logging.Logger.debugv = debugv + if get_conf()["MPD_WAIT_START"]: + while True: try: get_mpd_client(get_conf()) - except Exception: - logging.debug("Could not connect to MPD, waiting") + except Exception as exc: + print("exc", exc, file=sys.stderr) + logging.debug( + "Could not connect to MPD at (%s,%s), waiting", + get_conf()["MPD_HOST"], + get_conf()["MPD_PORT"], + ) sd_notify(status="Waiting MPD connection") sleep(int(get_conf()["MPD_WAIT_START_RETRYSECS"])) else: diff --git a/larigira/mpc.py b/larigira/mpc.py index 456081c..7027b86 100644 --- a/larigira/mpc.py +++ b/larigira/mpc.py @@ -157,6 +157,9 @@ class Player: reason = "Filtered by %s (%s)" % (entrypoint.name, reason) if ret is False: return ret, reason + else: + if reason: + self.log.debug('filter %s says ok: %s', entrypoint.name, reason) return True, "Passed through %s" % ",".join(availfilters) def enqueue(self, songs): @@ -224,7 +227,6 @@ class Controller(gevent.Greenlet): gevent.Greenlet.spawn(self.player.check_playlist) while True: value = self.q.get() - self.log.debug("<- %s", str(value)) # emitter = value['emitter'] kind = value["kind"] args = value["args"]