Reputation: 479
I've set up a SocketHandler but noticed it creates a binary output. I checked the docs and saw that it calls the "makePickle" function to create a binary output from the message record. I use dictConfig() to configure logging.
What I'd like to have is a plain text log message sent out to a TCP server without any pickling. I have two ideas in mind:
I can't decide which one is the better solution. Can you guys help me out? Also, if there's any other, easier and more straightforward way to achieve this I'm open to it.
Thanks
Upvotes: 1
Views: 994
Reputation: 479
If anyone has the same problem, I decided to create a custom handler based on Socket handler. Like so:
class PlainTextTcpHandler(handlers.SocketHandler):
""" Sends plain text log message over TCP channel """
def makePickle(self, record):
message = self.formatter.format(record) + "\r\n"
return message.encode()
And you can use this handler as any other default one.
Upvotes: 3