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
commit 601c75cab4a785a7c9028328218c0790657c618c Author: Robert Grizzell <[email protected]> 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
