You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/01/24 11:03:19 UTC

[GitHub] ashb commented on a change in pull request #3992: [AIRFLOW-620] Feature to tail custom number of logs instead of rendering whole log

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/airflow/pull/3992#discussion_r250558702
 
 

 ##########
 File path: airflow/utils/helpers.py
 ##########
 @@ -317,3 +317,45 @@ def render_log_filename(ti, try_number, filename_template):
                                     task_id=ti.task_id,
                                     execution_date=ti.execution_date.isoformat(),
                                     try_number=try_number)
+
+
+def tail_file(filepath, lines):
+    """
+    Tail last n lines from give file.
+    :param filepath: Path to the file we have to tail
+    :param lines: Number of lines to tail
+    :return last n lines in the file
+    """
+    def get_byte_range_file(fl, num_bytes):
+        # Get current position of file pointer
+        current_position = fl.tell()
+        if current_position < num_bytes:
+            num_bytes = current_position
+        if current_position == 0:
+            return None
+        fl.seek(-num_bytes, 1)
+        data = str(fl.read(num_bytes), 'utf-8', 'ignore')
+        fl.seek(-num_bytes, 1)
 
 Review comment:
   ```suggestion
           fl.seek(-num_bytes, os.SEEK_CUR)
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services