-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggers.py
58 lines (41 loc) · 1.15 KB
/
loggers.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
"""
module containing classes related to logging beerery data
"""
from pymongo import MongoClient
class Logger(object):
"""
base class for loggers
"""
def log_input(self, name, info_dict):
"""
log an input value
"""
pass
def log_output(self, name, info_dict):
"""
log an output value
"""
pass
class JsonFileLogger(Logger):
"""
logger that will eventually write to a local file
"""
def __init__(self, file_path):
pass
def log_input(self, name, info_dict):
pass
def log_output(self, name, info_dict):
pass
class MongoDBLogger(Logger):
"""
Logger that writes to a mongo db database
"""
def __init__(self, db_uri, database):
self.client = MongoClient(db_uri)
self.database = self.client[database]
def log_input(self, name, info_dict):
input_collection = self.database["input_{}".format(name)]
input_collection.insert(info_dict)
def log_output(self, name, info_dict):
output_collection = self.database["output_{}".format(name)]
output_collection.insert(info_dict)