ashb commented on a change in pull request #3992: [AIRFLOW-620] Feature to tail
custom number of logs instead of rendering whole log
URL: https://github.com/apache/incubator-airflow/pull/3992#discussion_r223699733
##########
File path: airflow/bin/cli.py
##########
@@ -1023,17 +1023,41 @@ def scheduler(args):
@cli_utils.action_logging
def serve_logs(args):
print("Starting flask")
- import flask
- flask_app = flask.Flask(__name__)
+ from flask import Flask, request, Response, stream_with_context,
send_from_directory
+ flask_app = Flask(__name__)
@flask_app.route('/log/<path:filename>')
def serve_logs(filename): # noqa
+ def tail_logs(logdir, filename, num_lines):
+ logpath = "{logdir}/{filename}".format(logdir=logdir,
filename=filename)
+ logsize = os.path.getsize(logpath)
+ if logsize >= 100 * 1024 * 1024:
+ p1 = subprocess.Popen(["tail", "-n " + str(num_lines),
filename],
+ stdout=subprocess.PIPE, cwd=log)
+ out, err = p1.communicate()
+ out = "Tailing file\n\n" + out.decode("utf-8")
+ else:
+ fl = open("{log}//{filename}".format(log=log,
filename=filename), "r")
+ lines = fl.readlines()
+ fl.close()
+ out = "".join(l for l in lines[-num_lines:])
+ line = "***** Showing only last {num_lines} lines from {filename}
*****" \
Review comment:
Messages like this don't belong in hereĀ - that is something that the
FileTaskHandler etc should add.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services