Connecting Spark Logs with Jupyter UI
I have successfully been able to show the kernel logs in realtime into the Jupyter front end.
So basically I configured the Jupyter kernel to dump the logs in real-time in a log file.
Then I created a new function that runs in a separate thread and pulls the content of the log file every 2 seconds.
Then the fetched data is sent to the front end via sockets every two seconds ONLY when the user opens the log.
So when the user is not in the logs page the socket communication and the reading of the log file do not happen.
def fetch_logs(comm):
f = open(“log.file”, “r”)
logs = f.read()
comm.send({‘status’ : ‘log_fetched_success’ , ‘log’ : logs})
if (ipython.ev(‘shouldFetchLog’)):
threading.Timer(2.0,fetch_logs, [comm]).start()