question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webserver shows wrong datetime (timezone) in log

See original GitHub issue

Apache Airflow version

2.2.1 (latest released)

Operating System

Ubuntu 20.04.2 (docker)

Versions of Apache Airflow Providers

  • apache-airflow-providers-amazon==2.3.0
  • apache-airflow-providers-ftp==2.0.1
  • apache-airflow-providers-http==2.0.1
  • apache-airflow-providers-imap==2.0.1
  • apache-airflow-providers-mongo==2.1.0
  • apache-airflow-providers-postgres==2.3.0
  • apache-airflow-providers-sqlite==2.0.1

Deployment

Docker-Compose

Deployment details

Docker image build on Ubuntu 20.04 -> installed apache airflow via pip. Localtime in image changed to Europe/Moscow.

Log format ariflow.cfg option: log_format = %%(asctime)s %%(filename)s:%%(lineno)d %%(levelname)s - %%(message)s

What happened

For my purposes it’s more usefull to run dags when it’s midnight in my timezone. So I changed default_timezone option in airflow.cfg to “Europe/Moscow” and also changed /etc/localtime in my docker image.

It works nice:

  • dags with @daily schedule_interval runs at midnight
  • python`s datetime.now() get me my localtime by default
  • airflow webserver shows all time correctly when I change timezone in right top corner

… except one thing. Python logging module saves asctime without timezone (for example “2021-10-31 18:25:42,550”). And when I open task`s log in web interface, it shifts this time forward by three hours (for my timzone), but it’s already in my timzone. It is a little bit confusing 😦

What you expected to happen

I expected to see my timezone in logs 😃

I see several solutions for that:

  1. any possibility to turn that shift off?
  2. setup logging timezone in airflow.cfg?

That problem is gone when I change system (in container) /etc/localtime to UTC. But this is very problematic because of the ability to affect a lot of python tasks.

How to reproduce

  1. build docker container with different /etc/localtime

FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y apt-utils locales tzdata
&& locale-gen en_US.UTF-8
&& ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en AIRFLOW_GPL_UNIDECODE=yes

RUN apt-get install -y
python3-pip
&& python3 -m pip install --upgrade pip setuptools wheel
&& pip3 install --no-cache-dir
apache-airflow-providers-amazon
apache-airflow-providers-mongo
apache-airflow-providers-postgres
apache-airflow==2.2.1
celery
… anything else

  1. run webserver / scheduler / celery worker inside
  2. open web page -> trigger dag with python operator which prints something via logging
  3. open done dag -> task log -> find asctime mark in log image
  4. switch timezone in web interface
  5. watch how airflow thinks that asctime in log in UTC, but it’s not image

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
calfzhoucommented, Dec 9, 2021

image

1reaction
aboriginecommented, Nov 23, 2021

I followed the merge code, but not fix this issue, the webserver still shows wrong datetime in log

What’s your server’s timezone and Airflow config’s default timezone?

I know what’s the problem, I should change the js file tiLog.478df866123cef0b0eae.js under ‘airflow/www/static/dist’ directly instead of ‘airflow/www/static/js/ti_log.js’. Once I restart the webserver, the datetime became the right one. Thanks for your reply anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webserver shows wrong datetime (timezone) in log (#23796)
I never waid assuming UTC is right, but the problem is the frontend doesn't know what timezone the log files used. Appending %z...
Read more >
Error Logging In: Date/Time or Timezone Are Wrong
When logging in, you may receive an error: "Your device clock or timezone is incorrect. Please change your Date & Time to be...
Read more >
Timestamp in Tomcat logs is wrong - Server Fault
The JVM might have the wrong timezone set as a default. Add a JVM option -Duser.timezone=US/Pacific (use the JAVA_OPTS property).
Read more >
Incorrect time stamps displayed by an application or in log files
The results display in the browser (which lists all valid time zones that the SDK knows about) and more details about the current...
Read more >
Q. IIS log file entries have an incorrect date and time stamp?
To resolve this issue, you can change the active logging format to the Microsoft IIS Log File Format, which logs in the server's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found