socket_log_receiver
is a light-weight socket log receiving server.
The server aggregates messages from multi-process applications via a
socket and logs them to a single file. The service is used with
Python's stdlib logging
package, which by default does not support
multi-process writes to a single file.
$ pip install socket-log-receiver
The receiver service should be run as a service:
$ python -m socket_log_receiver # as a module
$ log_receiver # as a command-line program
These are equivalent.
By default, the receiver service starts listening on localhost:9020
.
These can be changed through CLI options; see the Help section below.
In the application, use SocketHandler
to send logs to the receiver
service.
from logging.handlers import SocketHandler
handler = SocketHandler('localhost', 9020) # handler to send logs to localhost:9020
logging.root.addHandler(handler) # add the socket handler to the root logger
This way, the root logger sends logging messages to the receiver service.
$ python -m socket_log_receiver -h
$ log_receiver -h
The receiver service's configuration is managed by
resconfig. By default, the
dynamic configuration update is trigged by SIGHUP
. Some systems
might not make this signal available, in which case you could use a
different signal for the trigger using the command-line option, e.g.
$ log_receiver --reloader-signal SIGUSR2
$ pip install -e .[dev]
$ pre-commit install
$ pip install -e .[test]
$ pytest