summaryrefslogtreecommitdiff
path: root/plugin.video.embycon/resources/lib/simple_logging.py
blob: 05230d9f25148ae2d20ca53e5b0e265b80189e81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Gnu General Public License - see LICENSE.TXT

import encodings

import xbmc
import xbmcaddon
from json_rpc import json_rpc

class SimpleLogging():
    name = ""
    enable_logging = False

    def __init__(self, name):
        settings = xbmcaddon.Addon(id='plugin.video.embycon')
        prefix = settings.getAddonInfo('name')
        self.name = prefix + '.' + name
        params = {"setting": "debug.showloginfo"}
        setting_result = json_rpc('Settings.getSettingValue').execute(params)
        current_value = setting_result.get("result", None)
        if current_value is not None:
            self.enable_logging = current_value.get("value", False)
        xbmc.log("LOGGING_ENABLED %s : %s" % (self.name, str(self.enable_logging)), level=xbmc.LOGDEBUG)

    def __str__(self):
        return "LoggingEnabled: " + str(self.enable_logging)

    def error(self, fmt, *args, **kwargs):
        new_args = []
        # convert any unicode to utf-8 strings
        for arg in args:
            if isinstance(arg, unicode):
                new_args.append(arg.encode("utf-8"))
            else:
                new_args.append(arg)
        log_line = self.name + " (ERROR) -> " + fmt.format(*new_args)
        xbmc.log(log_line, level=xbmc.LOGDEBUG)

    def debug(self, fmt, *args, **kwargs):
        if self.enable_logging:
            new_args = []
            # convert any unicode to utf-8 strings
            for arg in args:
                if isinstance(arg, unicode):
                    new_args.append(arg.encode("utf-8"))
                else:
                    new_args.append(arg)
            log_line = self.name + " (DEBUG) -> " + fmt.format(*new_args)
            xbmc.log(log_line, level=xbmc.LOGDEBUG)