-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstores.py
46 lines (32 loc) · 1.25 KB
/
stores.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
import collections
import logging
import logging.handlers
import urlparse
class InMemoryStore(object):
def __init__(self, url):
qa = urlparse.parse_qs(url.query)
max_length = int(qa.get('max_length', ['100'])[0])
print 'Configuring in-memory store with {settings}'.format(settings={"max_length": max_length})
self.events = collections.deque(maxlen=max_length)
def save(self, event):
print event
self.events.append(event)
def list(self):
return list(self.events)
class SyslogUdpStore(object):
def __init__(self, url):
server = url.hostname
port = url.port or logging.handlers.SYSLOG_UDP_PORT
address = (server, port)
print 'Configuring syslog-udp store with {settings}'.format(settings={"server": server, "port": port})
self.log = logging.getLogger('marathon-logger')
facility = logging.handlers.SysLogHandler.LOG_USER
h = logging.handlers.SysLogHandler(address, facility)
f = logging.Formatter('marathon-logger: %(message)s')
h.setFormatter(f)
self.log.addHandler(h)
self.log.setLevel(logging.getLevelName('INFO'))
def save(self, event):
self.log.info(event)
def list(self):
return []