forked from Rafiot/PubSubLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_subscriber
executable file
·56 lines (46 loc) · 2.29 KB
/
log_subscriber
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import signal
from pubsublogger import subscriber
def signal_handler(signal, frame):
if subscriber.pubsub is not None:
subscriber.stop()
print("Subscriber closed.")
signal.signal(signal.SIGINT, signal_handler)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Configure a logging subscriber.')
parser.add_argument("-H", "--hostname", default='localhost',
type=str, help='Set the hostname of the server.')
parser.add_argument("-p", "--port", default=6379,
type=int, help='Set the server port.')
parser.add_argument('-s', '--use_unix_socket', action='store_true',
help='Use a unix socket path instead of a tcp socket.')
parser.add_argument("--unix_socket_path", default='/tmp/redis.sock',
type=str, help='Unix socket path.')
parser.add_argument("-c", "--channel",
type=str, required=True, help='Channel to subscribe to.')
parser.add_argument("-l", "--log_path",
required=True, help='Path where the logs will be written')
parser.add_argument("-d", "--debug", action="store_true",
help='Also log debug messages.')
parser.add_argument("-m", "--mail", type=str, default=None,
help='Path to the config file used to send errors by email.')
parser.add_argument("--syslog", action='store_true',
help='Enable syslog.')
parser.add_argument("-ss", "--syslog_server", type=str, default=None,
help='Host of the syslog server.')
parser.add_argument("-sp", "--syslog_port", type=int, default=514,
help='Port of the syslog server.')
parser.set_defaults(syslog=False)
args = parser.parse_args()
if args.use_unix_socket:
subscriber.unix_socket = args.unix_socket_path
else:
subscriber.hostname = args.hostname
subscriber.port = args.port
if args.syslog_server and args.syslog_port:
syslog_address = (args.syslog_server, int(args.syslog_port))
else:
syslog_address = None
subscriber.run(args.channel, args.log_path, args.debug, args.mail, args.syslog, syslog_address)