示例#1
0
文件: parser.py 项目: KLab/fluenpy
    def __call__(self, text):
        m = self.regexp.match(text)
        if not m:
            log.warn("pattern not match: pattern=%s, text=%r",
                     self.regexp.pattern, text)
            return None, None

        t = None
        record = {}

        for name, value in m.groupdict().iteritems():
            if value is None:
                continue
            if name == 'time':
                if self.time_format:
                    t = unix_strptime(value, self.time_format)
                else:
                    #TODO: Ruby だと Time.parse を使ってる.
                    #何か標準的なフォーマットでのパースを試行するべき.
                    t = float(value)
            else:
                record[name] = value

        if t is None:
            t = time.time()
        return t, record
示例#2
0
文件: parser.py 项目: KLab/fluenpy
    def record_map(self, record):
        t = None
        if self.time_key:
            value = record.pop(self.time_key)
            if self.time_format:
                t = unix_strptime(value, self.time_format)
            else:
                #TODO: 一般的なフォーマットでのparseを試みる
                t = float(value)

        if t is None:
            t = time.time()
        return t, record
示例#3
0
文件: parser.py 项目: KLab/fluenpy
    def __call__(self, text):
        record = loads(text)

        t = None
        try:
            value = record.pop(self.time_key)
            if value:
                if self.time_format is not None:
                    t = unix_strptime(value, self.time_format)
                else:
                    t = int(value)
        except KeyError:
            pass
        if t is None:
            t = time.time()

        return t, record
示例#4
0
文件: parser.py 项目: KLab/fluenpy
    def __call__(self, text):
        m = self.REGEXP.match(text)
        if not m:
            log.warn("pattern not match: %r", text)
            return None, None
        record = m.groupdict()

        for k in ('host', 'user', 'referer', 'agent'):
            if record[k] == '-':
                record[k] = None

        t = unix_strptime(record['time'], "%d/%b/%Y:%H:%M:%S %z")
        del record['time']

        try:
            record['code'] = int(record['code']) or None
        except ValueError:
            record['code'] = None
        try:
            record['size'] = int(record['size'])
        except ValueError:
            record['size'] = None

        return t, record