I want to write a record created by a logging handler to a webpage by passing that record through a Flask SocketIO socket (i.e. print the same log message I get at the console to a webpage).
I see many handlers are available, but none of them appear to readily suit this case. Maybe I need a custom handler?
class MessagePaneHandler:
# some log data is received
socketio.emit("event_name", log_message_from_handler, namespace="/some_namespace", broadcast=True)
Update:
As far as I can tell, the logging.handlers.SocketHandler writes to a raw TCP socket. Can I use a logging.handlers.SocketHandler to write to a Flask SocketIO socket instead? If so, how?
If it helps, this is how I set up my socket on the front end:
var socket = io.connect("http://" + document.domain + ":" + location.port + "/some_namespace");
SocketHandleris not what you want, that writes to a standard networking socket, which is much more lower lever than Socket.IO. I think you'll need to write your own logging handler, I'm not aware of any that sends logs via Socket.IO.