-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
76 lines (58 loc) · 2.8 KB
/
log.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import config as conf
import logging as log
import sys
# class LazyStreamHandler(log.StreamHandler):
# def emit(self, record) -> None:
# if self.buffer is None:
# self.buffer = []
# if len(self.buffer) >= 10000:
# self.buffer.append(record)
# self.buffer = None
# else:
# for rec in self.buffer:
# try:
# msg = self.format(rec)
# stream = self.stream
# stream.write(msg + self.terminator)
# except RecursionError: # See issue 36272
# raise
# except Exception:
# self.handleError(record)
# self.flush()
class Log:
def __init__(self):
log.basicConfig(stream=sys.stdout, level=log.INFO,
format='[%(asctime)s] [%(levelname)s] [%(scheme)s] [%(db)s]: %(message)s')
def info(self, msg, **kwargs):
log.info(msg, extra=self._construct_params(kwargs))
def error(self, msg, **kwargs):
log.error(msg, extra=self._construct_params(kwargs))
def exception(self, e, **kwargs):
log.exception(e, extra=self._construct_params(kwargs))
def batch_dynamic(self, count, time, table_name, **kwargs):
log.info('%s record(s) were inserted into the dynamic table %s in %s sec' % (
count, table_name, int(time)), extra=self._construct_params(kwargs))
def batch_include(self, batch_nb, count, table_name, latest, time, read_time, write_time, **kwargs):
log.info('Batch #%s: %s records were inserted into [%s] at %s. Total: %s sec (read=%s, write=%s)' % (
batch_nb, count, table_name, latest, int(time), int(read_time), int(write_time)), extra=self._construct_params(kwargs))
def database_created(self, **kwargs):
log.info('Database was created', extra=self._construct_params(kwargs))
def view_created(self, view_name, **kwargs):
log.info('View %s was created', extra=self._construct_params(kwargs))
def dynamic_recreated(self, table_name, **kwargs):
log.info('(re)creating dynamic table %s' %
(table_name), extra=self._construct_params(kwargs))
def reflecting_source(self, **kwargs):
log.info('Reflecting source database',
extra=self._construct_params(kwargs))
def reflecting_target(self, **kwargs):
log.info('Reflecting target database',
extra=self._construct_params(kwargs))
def bootstrapped_with(self, stmt, **kwargs):
log.info('Bootstrapped server with %s' %
(stmt), extra=self._construct_params(kwargs))
def _construct_params(self, kwargs):
return {
'scheme': kwargs.get('scheme', None) or '',
'db': kwargs.get('db', None) or ''
}