TCP logging on FluentBit from Python #5823
-
Trying to export logs to a fluent-bit TCP input server, from a Python module. fluent-bit is setup to listen to a localhost port with a TCP server, and in Python the logging creates a SocketHandler logging handler, to redirect the logs on that port. Python:
fluent-bit.conf
parsers.conf
When the format is set to json in the fluent-bit.conf, fluent-bit return the error:
and when it set to none, the error is:
Has anybody been able to intergrate fluent-bit TCP server, with Python, and solve the above problem? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@cosmo0920 this issue was showing up with other tcp agents as well, I'm wondering if there is something we can add to help parse / debug these types of issues |
Beta Was this translation helpful? Give feedback.
-
Hi, I wanted to hop in here as well. Trying @msSarriman code I experience the same, my td-agent-bit reports only this:
I tried both with a formatter and without, still no use. Then I tried using python's `socket' module and it does seem to catch the data, at least some of it. This is the test code: from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.connect(("localhost", 6969))
string = "This is my string\n\nAFTER_IT" # AFTER IT doesn't appear on fluent bit
s.sendall(string.encode())
s.close() And this is the result on fluent bit:
I didn't try the HTTP plugin to do logging but I don't really feel comfortable having to change my logger to perform Hope this helps and hope to see some insight about this issue. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this thread. Turns out Here's a handler which works from logging.handlers import SocketHandler
class FluentBitHandler(SocketHandler):
def emit(self, record):
try:
self.send((self.format(record)).encode())
except Exception:
self.handleError(record) Of source you need to make sure the format is JSON. |
Beta Was this translation helpful? Give feedback.
Thanks for this thread. Turns out
logging.handlers.SockeHandler
pickles the message before sending in theemit
method for some reason. Remove the pickles will work.Here's a handler which works
Of source you need to make sure the format is JSON.