Like with --logfile this commit adds support for using
an existing Unix Domain Socket for logging. It's required
that there is a listener on the given socket otherwise
kiwi exits with an appropriate error message from the
socket layer. A simple listener could look like the
following:
```python
sock_file = '/tmp/log_socket'
buffer = 1024
if os.path.exists(sock_file):
os.unlink(sock_file)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(sock_file)
sock.listen(1)
while True:
connection, client_address = sock.accept()
try:
while True:
data = connection.recv(buffer)
if not data:
break
print(data.decode())
finally:
connection.close()
```
With the listener in place kiwi can be called as follows:
kiwi-ng --logsocket /tmp/log_socket ...
16 lines
460 B
Python
16 lines
460 B
Python
from mock import Mock
|
|
from kiwi.logger_socket import PlainTextSocketHandler
|
|
|
|
|
|
class TestPlainTextSocketHandler:
|
|
def setup(self):
|
|
self.logger_socket = PlainTextSocketHandler('socket', None)
|
|
self.logger_socket.formatter = Mock()
|
|
|
|
def setup_method(self, cls):
|
|
self.setup()
|
|
|
|
def test_makePickle(self):
|
|
self.logger_socket.makePickle('record')
|
|
self.logger_socket.formatter.format.assert_called_once_with('record')
|