-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.py
34 lines (23 loc) · 1.03 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
from datetime import datetime
def log(s):
time = '%s' % datetime.now()
for line in s.split('\n'):
print('%s: %s' % (time, line))
def log_event(event, objtype, obj, params=None):
if params is not None:
if type(params) == dict:
params = ', '.join([
('%s: %s' % (k, v) if type(v) != bool else k)
for (k, v) in filter(lambda e: e[0] is not None and (type(e[1]) != bool or e[1] == True), {
k.replace('_', ' '): v
for (k, v) in params.items()
}.items())
])
params = ' (%s)' % params if params is not None else ''
log('%-8s %-4s %s%s' % (event, objtype, obj, params))
def log_tx_event(tx, event, **kwargs):
log_event(event, 'tx', tx, kwargs if kwargs != {} else None)
def log_block_event(block, event, **kwargs):
log_event(event, 'blk', block, kwargs if kwargs != {} else None)
def log_balance_event(address, event, **kwargs):
log_event(event, 'bal', address, kwargs if kwargs != {} else None)