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_r224698554
##########
File path: airflow/utils/log/file_task_handler.py
##########
@@ -94,17 +95,38 @@ def _read(self, ti, try_number, metadata=None):
# is needed to get correct log path.
log_relative_path = self._render_filename(ti, try_number)
location = os.path.join(self.local_base, log_relative_path)
+ if metadata and "num_lines" in metadata:
+ num_lines = metadata.num_lines
+ else:
+ num_lines = None
log = ""
if os.path.exists(location):
- try:
- with open(location) as f:
- log += "*** Reading local file: {}\n".format(location)
- log += "".join(f.readlines())
- except Exception as e:
- log = "*** Failed to load local log file:
{}\n".format(location)
- log += "*** {}\n".format(str(e))
+ if num_lines:
Review comment:
There is a lot of duplicate logic in this one with the `tail_logs` function.
----------------------------------------------------------------
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