You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2020/12/01 00:07:00 UTC

[airflow] branch v1-10-test updated: Fix empty asctime field in JSON formatted logs (#10515)

This is an automated email from the ASF dual-hosted git repository.

kaxilnaik pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v1-10-test by this push:
     new a6d323f  Fix empty asctime field in JSON formatted logs (#10515)
a6d323f is described below

commit a6d323fd5bbbf06687cf46120914a33e66e07460
Author: Robert Grizzell <ro...@grizzell.me>
AuthorDate: Wed Sep 16 11:50:27 2020 -0500

    Fix empty asctime field in JSON formatted logs (#10515)
    
    (cherry picked from commit 2aec99c22847594040d28e587ab5e2473eff8c94)
---
 airflow/utils/log/json_formatter.py    | 3 +++
 tests/utils/log/test_json_formatter.py | 9 +++++++++
 2 files changed, 12 insertions(+)

diff --git a/airflow/utils/log/json_formatter.py b/airflow/utils/log/json_formatter.py
index 1d90bc3..3cf4530 100644
--- a/airflow/utils/log/json_formatter.py
+++ b/airflow/utils/log/json_formatter.py
@@ -53,6 +53,9 @@ class JSONFormatter(logging.Formatter):
         self.json_fields = json_fields
         self.extras = extras
 
+    def usesTime(self):
+        return self.json_fields.count('asctime') > 0
+
     def format(self, record):
         super(JSONFormatter, self).format(record)
         record_dict = {label: getattr(record, label, None)
diff --git a/tests/utils/log/test_json_formatter.py b/tests/utils/log/test_json_formatter.py
index 5c305c9..1608d81 100644
--- a/tests/utils/log/test_json_formatter.py
+++ b/tests/utils/log/test_json_formatter.py
@@ -75,6 +75,15 @@ class TestJSONFormatter(unittest.TestCase):
         merged = merge_dicts(dict1, dict2)
         self.assertDictEqual(merged, {'a': 1, 'r': {'b': 0, 'c': 3}})
 
+    def test_uses_time(self):
+        """
+        Test usesTime method from JSONFormatter
+        """
+        json_fmt_asctime = JSONFormatter(json_fields=["asctime", "label"])
+        json_fmt_no_asctime = JSONFormatter(json_fields=["label"])
+        self.assertTrue(json_fmt_asctime.usesTime())
+        self.assertFalse(json_fmt_no_asctime.usesTime())
+
     def test_format(self):
         """
         Test format method from JSONFormatter