forked from fedora-infra/fedmsg
/
logger.py
49 lines (40 loc) · 1.16 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import fedmsg
from fedmsg.commands import command
def _log_message(kw, message):
fedmsg.send_message(
topic=kw['topic'],
msg={'log': message},
modname='logger',
)
extra_args = [
(['--relay'], {
'dest': 'relay',
'help': "Endpoint of the log relay fedmsg-hub to connect to",
'default': "tcp://127.0.0.1:3002",
}),
(['--message'], {
'dest': 'message',
'help': "The message to send.",
}),
([], {
'dest': 'topic',
'metavar': "TOPIC",
'help': "Think org.fedoraproject.logger.TOPIC",
}),
]
@command(extra_args=extra_args)
def logger(**kwargs):
""" Emit log messages to the FI bus.
If --message is not specified, this command accepts messages from stdin.
"""
kwargs['active'] = True
kwargs['endpoints']['relay_inbound'] = kwargs['relay_inbound']
fedmsg.init(name='relay_inbound', **kwargs)
if kwargs.get('message', None):
_log_message(kwargs, kwargs['message'])
else:
line = sys.stdin.readline()
while line:
_log_message(kwargs, line.strip())
line = sys.stdin.readline()