Fokko 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_r224698318
##########
File path: airflow/bin/cli.py
##########
@@ -1023,17 +1023,39 @@ 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")
Review comment:
Can we move out the `tail_logs` function out of this function? This is very
unreadable
----------------------------------------------------------------
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