Send to logstash
✓ Published0🌍 Public
WWilliamQLiu
Last edited Apr 3, 2018
Created on Apr 2, 2018
This example demonstrates how to send a JSON-formatted log message to a Logstash instance over a TCP socket. It defines a `log_msg` function that creates a socket connection to a specified host and port, serializes the message dictionary using `json.dumps`, and transmits it with `sock.send`. The code uses Python’s `socket` library for the network communication and `json` for encoding, with error handling that writes to `stderr` and exits on connection failures. The sample message structure includes fields like `@message` and `@tags`, but the function itself accepts any dictionary.
AI-generated description