# Path: XulDebugTool/controller/ConsoleDeskController.py
# class ConsoleController(object):
# 
#     @classmethod
#     def windowPrintInfo(self, loggername, mode, msg):
#         windowStr = LogFormatTool.buildStandardTime() + " - " + loggername + " - " + mode + " - "
# 
#         print(windowStr, end=' ')
#         for text in msg:
#             print(self.getLogContent(self, text), end=' ')
#         print("<br />")
#         return
# 
#     def getLogContent(self, text):
#         if isinstance(text, str):
#             regexUrl = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+",
#                                   re.IGNORECASE)
#             urls = regexUrl.findall(text)
#             for url in urls:
#                 preS = "<a href=\"" + url + "\">" + url + "</a>"
#                 text = text.replace(url, preS)
# 
#         return text
# 
# Path: XulDebugTool/utils/ConfigHelper.py
# class ConfigHelper(object):
#     LOGCATPATH = ""
# 
#     #以下是配置信息所对应的key
#     KEY_LOGCATPATH = 'logcatPath'
# 
#     @staticmethod
#     def initLogConfigPath():
#         ConfigHelper.LOGCATPATH = ConfigurationDB.getConfiguration(ConfigHelper.KEY_LOGCATPATH)
#         if len(ConfigHelper.LOGCATPATH)<=0:
#             ConfigHelper.LOGCATPATH = str(os.getcwd()) + "\logcat.txt"
#             ConfigurationDB.saveConfiguration(ConfigHelper.KEY_LOGCATPATH,ConfigHelper.LOGCATPATH)


import logging
from XulDebugTool.controller.ConsoleDeskController import ConsoleController
from XulDebugTool.utils.ConfigHelper import ConfigHelper

    def w(self, *args):
        self.logger.warning(args)
        self.filterLog(self.WARNING, args)
        self.removeHandler()
        return

    def i(self, *args):
        self.logger.info(args)
        self.filterLog(self.INFO, args)
        self.removeHandler()
        return

    def d(self, *args):
        self.logger.debug(args)
        self.filterLog(self.DEBUG, args)
        self.removeHandler()
        return

    def c(self, *args):
        self.logger.critical(args)
        self.filterLog(self.CRITICAL, args)
        self.removeHandler()
        return



    def filterLog(self,mode, args):
        preLevel = self.getCurLogLevel(mode)
        if preLevel >= self.level:

# Path: XulDebugTool/controller/ConsoleDeskController.py
# class ConsoleController(object):
# 
#     @classmethod
#     def windowPrintInfo(self, loggername, mode, msg):
#         windowStr = LogFormatTool.buildStandardTime() + " - " + loggername + " - " + mode + " - "
# 
#         print(windowStr, end=' ')
#         for text in msg:
#             print(self.getLogContent(self, text), end=' ')
#         print("<br />")
#         return
# 
#     def getLogContent(self, text):
#         if isinstance(text, str):
#             regexUrl = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+",
#                                   re.IGNORECASE)
#             urls = regexUrl.findall(text)
#             for url in urls:
#                 preS = "<a href=\"" + url + "\">" + url + "</a>"
#                 text = text.replace(url, preS)
# 
#         return text
# 
# Path: XulDebugTool/utils/ConfigHelper.py
# class ConfigHelper(object):
#     LOGCATPATH = ""
# 
#     #以下是配置信息所对应的key
#     KEY_LOGCATPATH = 'logcatPath'
# 
#     @staticmethod
#     def initLogConfigPath():
#         ConfigHelper.LOGCATPATH = ConfigurationDB.getConfiguration(ConfigHelper.KEY_LOGCATPATH)
#         if len(ConfigHelper.LOGCATPATH)<=0:
#             ConfigHelper.LOGCATPATH = str(os.getcwd()) + "\logcat.txt"
#             ConfigurationDB.saveConfiguration(ConfigHelper.KEY_LOGCATPATH,ConfigHelper.LOGCATPATH)


# Path: XulDebugTool/logcatapi/Logcat.py
import logging
from XulDebugTool.controller.ConsoleDeskController import ConsoleController
from XulDebugTool.utils.ConfigHelper import ConfigHelper


    def w(self, *args):
        self.logger.warning(args)
        self.filterLog(self.WARNING, args)
        self.removeHandler()
        return

    def i(self, *args):
        self.logger.info(args)
        self.filterLog(self.INFO, args)
        self.removeHandler()
        return

    def d(self, *args):
        self.logger.debug(args)
        self.filterLog(self.DEBUG, args)
        self.removeHandler()
        return

    def c(self, *args):
        self.logger.critical(args)
        self.filterLog(self.CRITICAL, args)
        self.removeHandler()
        return



    def filterLog(self,mode, args):
        preLevel = self.getCurLogLevel(mode)
        if preLevel >= self.level:

            ConsoleController.windowPrintInfo(self.loggername, mode, args)