forked from KMI-KPZ/geo-L
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
58 lines (45 loc) · 2.36 KB
/
logger.py
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
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os.path import join
from time import time
import logging
class ErrorLogger:
def __init__(self, name, error_type, query_hash):
self.logger = logging.getLogger('{}_{}'.format(query_hash, name))
self.logger.setLevel(logging.ERROR)
self.logger.propagate = False
logger_handler = logging.FileHandler(join('logs', '{}_{}.log'.format(query_hash, error_type)))
logger_handler.setLevel(logging.ERROR)
logger_formater = logging.Formatter('%(message)s')
logger_handler.setFormatter(logger_formater)
self.logger.addHandler(logger_handler)
class ResultLogger:
def __init__(self, name, source_hash, source_offset, source_limit, relation,target_hash,target_offset, target_limit):
self.logger = logging.getLogger('{}#{}#{}_{}_{}#{}#{}_{}'.format(source_hash, source_offset, source_limit, relation, target_hash, target_offset, target_limit, name))
self.logger.setLevel(logging.INFO)
self.logger.propagate = False
logger_handler = logging.FileHandler(join('output', '{}#{}#{}_{}_{}#{}#{}.log'.format(source_hash, source_offset, source_limit, relation, target_hash, target_offset, target_limit)), mode='w')
logger_handler.setLevel(logging.INFO)
logger_formater = logging.Formatter('%(message)s')
logger_handler.setFormatter(logger_formater)
self.logger.addHandler(logger_handler)
class InfoLogger:
def __init__(self, name, query_hash):
self.logger = logging.getLogger('{}_{}_{}'.format(name, query_hash, time()))
self.logger.setLevel(logging.INFO)
logger_formater = logging.Formatter('%(asctime)s - %(message)s')
logger_handler = logging.StreamHandler()
logger_handler.setLevel(logging.INFO)
logger_handler.setFormatter(logger_formater)
self.logger.addHandler(logger_handler)
logger_handler = logging.FileHandler(join('logs', '{}.log'.format(query_hash)))
logger_handler.setLevel(logging.INFO)
logger_handler.setFormatter(logger_formater)
self.logger.addHandler(logger_handler)
def load_logfile(query_hash, error_type):
try:
with open(join('logs', '{}_{}.log'.format(query_hash, error_type))) as logfile:
content = logfile.readlines()
return [line.strip() for line in content]
except:
return []