Ejemplo n.º 1
0
    def __init__(self, logfile, loglevel, stream, name=None):
        """ __init__(self, name = None)

            Initializes the logging driver and loads necessary config
            values from the ConfigurationSection that should be passed
            in as config. Also loads the root logger from a specified
            default name or from the base module name of the package.
        """

        if not name:
            self.name = get_caller().split(".")[0]
        else:
            self.name = name

        self.__logfile = logfile
        self.__stream = stream

        if isinstance(loglevel, int):
            self.__loglevel = loglevel
        else:
            self.__loglevel = getattr(logging, loglevel, None)
            if not isinstance(self.__loglevel, int):
                raise TypeError("Invalid log level: {}".format(loglevel))

        LoggingDriver.__instances.update({self.name: self})

        self.__setup_logger()
Ejemplo n.º 2
0
    def __init__(self, logfile, loglevel, stream, name=None):
        """ __init__(self, name = None)

            Initializes the logging driver and loads necessary config
            values from the ConfigurationSection that should be passed
            in as config. Also loads the root logger from a specified
            default name or from the base module name of the package.
        """

        if not name:
            self.name = get_caller().split('.')[0]
        else:
            self.name = name

        self.__logfile = logfile
        self.__stream = stream

        if isinstance(loglevel, int):
            self.__loglevel = loglevel
        else:
            self.__loglevel = getattr(logging, loglevel, None)
            if not isinstance(self.__loglevel, int):
                raise TypeError("Invalid log level: {}".format(loglevel))

        LoggingDriver.__instances.update({self.name: self})

        self.__setup_logger()
Ejemplo n.º 3
0
    def get_instance(cls, name=None):

        if name is None:
            name = get_caller().split(".")[0]

        if not cls.__instances or name not in cls.__instances:
            return None

        return cls.__instances.get(name)
Ejemplo n.º 4
0
    def get_instance(cls, name=None):

        if name is None:
            name = get_caller().split('.')[0]

        if not cls.__instances or name not in cls.__instances:
            return None

        return cls.__instances.get(name)
Ejemplo n.º 5
0
    def find_logger(cls, name=None):

        if name is None:
            name = get_caller()
            root = name.split(".")[0]
        else:
            root = name

        if not cls.get_instance(name=root):
            return None

        return cls.get_instance(name=root).get_logger(name=name)
Ejemplo n.º 6
0
    def get_logger(self, name=None):
        """ get_logger(self, name = None)

            Will return a logger object for a specific namespace.
            If name parameter is None, get_logger will use call
            stack inspection to get the namespace of the last caller.
        """

        if name is None:
            name = get_caller()

        return logging.getLogger(name)
Ejemplo n.º 7
0
    def find_logger(cls, name=None):

        if name is None:
            name = get_caller()
            root = name.split('.')[0]
        else:
            root = name

        if not cls.get_instance(name=root):
            return None

        return cls.get_instance(name=root).get_logger(name=name)
Ejemplo n.º 8
0
    def get_logger(self, name=None):
        """ get_logger(self, name = None)

            Will return a logger object for a specific namespace.
            If name parameter is None, get_logger will use call
            stack inspection to get the namespace of the last caller.
        """

        if name is None:
            name = get_caller()

        return logging.getLogger(name)
Ejemplo n.º 9
0
    def from_config(cls, config, name=None):

        if not name:
            name = get_caller().split(".")[0]
        else:
            name = name

        logfile = config.get_string("logfile", "/var/log/{}.log".format(name))
        loglevel = config.get_string("loglevel", "INFO").upper()
        stream = config.get_bool("console_log", True)

        loglevel = getattr(logging, loglevel, None)
        if not isinstance(loglevel, int):
            raise TypeError("Invalid log level: {}".format(config.get_string("loglevel", "INFO").upper()))

        return cls(logfile=logfile, loglevel=loglevel, stream=stream, name=name)
Ejemplo n.º 10
0
    def from_config(cls, config, name=None):

        if not name:
            name = get_caller().split('.')[0]
        else:
            name = name

        logfile = config.get_string("logfile", "/var/log/{}.log".format(name))
        loglevel = config.get_string("loglevel", "INFO").upper()
        stream = config.get_bool("console_log", True)

        loglevel = getattr(logging, loglevel, None)
        if not isinstance(loglevel, int):
            raise TypeError("Invalid log level: {}".format(
                config.get_string("loglevel", "INFO").upper()))

        return cls(logfile=logfile,
                   loglevel=loglevel,
                   stream=stream,
                   name=name)