-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_proxy.py
30 lines (24 loc) · 1008 Bytes
/
log_proxy.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
import queue
class LogProxy:
def __init__(self, destinations: list):
self.destinations: list = destinations
self.log_queues: dict = {
# destination
# for destination in destinations
} #字典推导式
# print(self.destinations,self.log_queues)
def add_log(self, level, content, destination):
if destination in self.destinations:
self.log_queues[destination].put((level,content))
else:
raise ValueError("Invalid destination: {}".format(destination))
# def get_num_destinations(self):
# return len(self.log_queues)
def add_destination(self, destination: str):
if destination not in self.destinations:
self.destinations.append(destination)
self.log_queues[destination] = queue.Queue()
else:
return
# raise ValueError(
# "Destination already exists: {}".format(destination))