コード例 #1
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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()
コード例 #2
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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()
コード例 #3
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #4
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #5
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #6
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #7
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #8
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #9
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)
コード例 #10
0
ファイル: log.py プロジェクト: gitter-badger/malibu
    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)