mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Merge pull request #193 from druscoe/inefficeint_usage_of_json_dumps_in_debug_output
Replaced debug output of json.dumps with an indirection to lazy __str__.
This commit is contained in:
commit
0e4458fa75
5 changed files with 22 additions and 5 deletions
|
@ -16,6 +16,7 @@ from database import reset, get_sync, Database, jellyfin_db, get_credentials
|
|||
from objects import Objects, Actions
|
||||
from downloader import TheVoid
|
||||
from helper import translate, event, settings, window, dialog, api, JSONRPC
|
||||
from helper.utils import JsonDebugPrinter
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
@ -45,7 +46,7 @@ class Events(object):
|
|||
if server == 'None':
|
||||
server = None
|
||||
|
||||
LOG.info("path: %s params: %s", path, json.dumps(params, indent=4))
|
||||
LOG.info("path: %s params: %s", path, JsonDebugPrinter(params))
|
||||
|
||||
if '/extrafanart' in base_url:
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import setup
|
|||
import monitor
|
||||
from views import Views, verify_kodi_defaults
|
||||
from helper import translate, window, settings, event, dialog
|
||||
from helper.utils import JsonDebugPrinter
|
||||
from jellyfin import Jellyfin
|
||||
|
||||
#################################################################################################
|
||||
|
@ -171,7 +172,7 @@ class Service(xbmc.Monitor):
|
|||
|
||||
data = json.loads(data)
|
||||
|
||||
LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4))
|
||||
LOG.debug("[ %s: %s ] %s", sender, method, JsonDebugPrinter(data))
|
||||
|
||||
if method == 'ServerOnline':
|
||||
if data.get('ServerId') is None:
|
||||
|
|
|
@ -494,3 +494,16 @@ def has_attribute(obj, name):
|
|||
return True
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
||||
class JsonDebugPrinter(object):
|
||||
|
||||
''' Helper class to defer converting data to JSON until it is needed.
|
||||
See: https://github.com/jellyfin/jellyfin-kodi/pull/193
|
||||
'''
|
||||
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
||||
def __str__(self):
|
||||
return json.dumps(self.data, indent=4)
|
||||
|
|
|
@ -11,6 +11,7 @@ import requests
|
|||
from six import string_types
|
||||
|
||||
from .exceptions import HTTPException
|
||||
from helper.utils import JsonDebugPrinter
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
@ -80,7 +81,7 @@ class HTTP(object):
|
|||
raise AttributeError("Request cannot be empty")
|
||||
|
||||
data = self._request(data)
|
||||
LOG.debug("--->[ http ] %s", json.dumps(data, indent=4))
|
||||
LOG.debug("--->[ http ] %s", JsonDebugPrinter(data))
|
||||
retry = data.pop('retry', 5)
|
||||
|
||||
while True:
|
||||
|
@ -162,7 +163,7 @@ class HTTP(object):
|
|||
elapsed = int(r.elapsed.total_seconds() * 1000)
|
||||
response = r.json()
|
||||
LOG.debug("---<[ http ][%s ms]", elapsed)
|
||||
LOG.debug(json.dumps(response, indent=4))
|
||||
LOG.debug(JsonDebugPrinter(response))
|
||||
|
||||
return response
|
||||
except ValueError:
|
||||
|
|
|
@ -16,6 +16,7 @@ import player
|
|||
from client import get_device_id
|
||||
from objects import PlaylistWorker, on_play, on_update, special_listener
|
||||
from helper import translate, settings, window, dialog, api, JSONRPC
|
||||
from helper.utils import JsonDebugPrinter
|
||||
from jellyfin import Jellyfin
|
||||
from webservice import WebService
|
||||
|
||||
|
@ -96,7 +97,7 @@ class Monitor(xbmc.Monitor):
|
|||
|
||||
data = json.loads(data)
|
||||
|
||||
LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4))
|
||||
LOG.debug("[ %s: %s ] %s", sender, method, JsonDebugPrinter(data))
|
||||
|
||||
if self.sleep:
|
||||
LOG.info("System.OnSleep detected, ignore monitor request.")
|
||||
|
|
Loading…
Reference in a new issue