#!/usr/bin/python3 # -*- coding: utf-8 -*- # An adjustment of the `jupyter-notebook' executable patched to: # - log to the ELK stack # # We go straight for the notebook executable here, as the "jupyter" command # execvp's into the requested notebook subcommand, erasing all configuration # we set here. import re import sys from notebook.notebookapp import main from logstash_async.handler import AsynchronousLogstashHandler, LogstashFormatter import logging if __name__ == '__main__': # log to the tcp_input of logstash in our ELK stack handler = AsynchronousLogstashHandler("elk", 5959, database_path='/tmp/pending_log_messages.db') # add to logger of Jupyter traitlets Application. As that logger is configured not to propagate # messages upward, we need to configure it directly. logger = logging.getLogger("NotebookApp") logger.addHandler(handler) logger.setLevel(logging.DEBUG) sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(main())