-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing Logs to Elasticsearch: asctime field in JSON log output set to null #10024
Comments
Thanks for opening your first issue here! Be sure to follow the issue template! |
A further deep dive into this issue, I believe this is the result of default behavior in the Python logging module. When utilizing the PercentStyle Formatter (as the JSONFormatter does by default with This is important because if But wait, if the WorkaroundThe following patch is a workaround for this issue that demonstrates the behavior of the standard logging library. Index: airflow/utils/log/json_formatter.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- airflow/utils/log/json_formatter.py (revision c35a01037ad4bb03d39a0319d37bc36b08ccf766)
+++ airflow/utils/log/json_formatter.py (date 1598039818218)
@@ -25,6 +25,7 @@
from airflow.utils.helpers import merge_dicts
+JSON_FMT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
class JSONFormatter(logging.Formatter):
"""
@@ -32,6 +33,8 @@
"""
# pylint: disable=too-many-arguments
def __init__(self, fmt=None, datefmt=None, style='%', json_fields=None, extras=None):
+ if fmt is None:
+ fmt = JSON_FMT
super().__init__(fmt, datefmt, style)
if extras is None:
extras = {} This patch generates the following log message:
|
Apache Airflow version: 1.10.11
Kubernetes version (if you are using kubernetes) (use
kubectl version
): N/AEnvironment:
uname -a
): 5.4.0-42-generic (and 5.6.6-300.fc32.x86_64)What happened:
If Airflow is set to log in Plaintext, it will print the log messages with
asctime
properly set.[2020-07-22 15:13:13,783] {standard_task_runner.py:54} INFO - Started process 116982 to run task
With the configuration changes to print to JSON,
asctime
is set tonull
.{"asctime": null, "task_id": "runme_0", "execution_date": "2020_07_23T00_00_00_000000", "filename": "standard_task_runner.py", "lineno": 54, "message": "Started process 281332 to run task", "try_number": "1", "levelname": "INFO", "dag_id": "example_bash_operator"}
What you expected to happen:
The
asctime
field should contain a proper timestamp when the log message is printed in JSON.How to reproduce it:
Using any standard default Airflow installation with the Elasticsearch subpackage installed, follow the instructions for Writing Logs to Elasticsearch. A running Elasticsearch instance is not required to reproduce this bug.
Diff of changes to `airflow.cfg`
Run the
example_bash_operator
DAG to generate log output. Check log files or stdout for JSON output.Anything else we need to know:
I was able to reproduce this pretty consistently regardless of the environment I was testing in, however I never bothered to try setting the configuration via Environment Variables nor did I try to run it in any sort of containerized environment (such as Kubernetes).
The text was updated successfully, but these errors were encountered: