You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by fo...@apache.org on 2018/01/10 11:56:30 UTC

incubator-airflow git commit: [AIRFLOW-1976] Fix for missing log/logger attribute FileProcessHandler

Repository: incubator-airflow
Updated Branches:
  refs/heads/master 37a1484f7 -> ffc4a8b41


[AIRFLOW-1976] Fix for missing log/logger attribute FileProcessHandler

Closes #2922 from
NielsZeilemaker/fix_log_file_process_handler


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/ffc4a8b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/ffc4a8b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/ffc4a8b4

Branch: refs/heads/master
Commit: ffc4a8b41c9a4554c47e1c7f8f70d93a40e3ddf8
Parents: 37a1484
Author: niels <ni...@zeilemaker.nl>
Authored: Wed Jan 10 12:56:25 2018 +0100
Committer: Fokko Driesprong <fo...@godatadriven.com>
Committed: Wed Jan 10 12:56:25 2018 +0100

----------------------------------------------------------------------
 airflow/utils/log/file_processor_handler.py    |  6 +++---
 tests/utils/log/test_file_processor_handler.py | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/ffc4a8b4/airflow/utils/log/file_processor_handler.py
----------------------------------------------------------------------
diff --git a/airflow/utils/log/file_processor_handler.py b/airflow/utils/log/file_processor_handler.py
index 8559e38..176e316 100644
--- a/airflow/utils/log/file_processor_handler.py
+++ b/airflow/utils/log/file_processor_handler.py
@@ -108,15 +108,15 @@ class FileProcessorHandler(logging.Handler):
                         os.symlink(log_directory, latest_log_directory_path)
                 elif (os.path.isdir(latest_log_directory_path) or
                           os.path.isfile(latest_log_directory_path)):
-                    self.log.warning(
+                    logging.warning(
                         "%s already exists as a dir/file. Skip creating symlink.",
                         latest_log_directory_path
                     )
                 else:
                     os.symlink(log_directory, latest_log_directory_path)
             except OSError:
-                self.logger.warning("OSError while attempting to symlink "
-                                    "the latest log directory")
+                logging.warning("OSError while attempting to symlink "
+                                "the latest log directory")
 
     def _init_file(self, filename):
         """

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/ffc4a8b4/tests/utils/log/test_file_processor_handler.py
----------------------------------------------------------------------
diff --git a/tests/utils/log/test_file_processor_handler.py b/tests/utils/log/test_file_processor_handler.py
index 8a3bbd2..de4cd2f 100644
--- a/tests/utils/log/test_file_processor_handler.py
+++ b/tests/utils/log/test_file_processor_handler.py
@@ -86,5 +86,24 @@ class TestFileProcessorHandler(unittest.TestCase):
             self.assertEqual(os.path.basename(os.readlink(link)), date2)
             self.assertTrue(os.path.exists(os.path.join(link, "log2")))
 
+    def test_symlink_latest_log_directory_exists(self):
+        handler = FileProcessorHandler(base_log_folder=self.base_log_folder,
+                                       filename_template=self.filename)
+        handler.dag_dir = self.dag_dir
+
+        date1 = (timezone.utcnow() + timedelta(days=1)).strftime("%Y-%m-%d")
+
+        p1 = os.path.join(self.base_log_folder, date1, "log1")
+        if os.path.exists(p1):
+            os.remove(p1)
+
+        link = os.path.join(self.base_log_folder, "latest")
+        if os.path.exists(link):
+            os.remove(link)
+        os.makedirs(link)
+
+        with freeze_time(date1):
+            handler.set_context(filename=os.path.join(self.dag_dir, "log1"))
+
     def tearDown(self):
         shutil.rmtree(self.base_log_folder, ignore_errors=True)