Skip to content

Commit

Permalink
Fix apache#23796 by adding %z in %(asctime)s
Browse files Browse the repository at this point in the history
  • Loading branch information
rino0601 committed Jun 23, 2022
1 parent 0905e38 commit d589b9d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
8 changes: 5 additions & 3 deletions airflow/config_templates/airflow_local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# settings.py and cli.py. Please see AIRFLOW-1455.
LOG_LEVEL: str = conf.get_mandatory_value('logging', 'LOGGING_LEVEL').upper()


# Flask appbuilder's info level log is very verbose,
# so it's set to 'WARN' by default.
FAB_LOG_LEVEL: str = conf.get_mandatory_value('logging', 'FAB_LOGGING_LEVEL').upper()
Expand Down Expand Up @@ -60,10 +59,13 @@
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'airflow': {'format': LOG_FORMAT},
'airflow': {
'format': LOG_FORMAT,
'class': 'airflow.utils.log.timezone_aware.TimezoneAware',
},
'airflow_coloured': {
'format': COLORED_LOG_FORMAT if COLORED_LOG else LOG_FORMAT,
'class': COLORED_FORMATTER_CLASS if COLORED_LOG else 'logging.Formatter',
'class': COLORED_FORMATTER_CLASS if COLORED_LOG else 'airflow.utils.log.timezone_aware.TimezoneAware',
},
},
'filters': {
Expand Down
2 changes: 2 additions & 0 deletions airflow/utils/log/colored_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CustomTTYColoredFormatter(TTYColoredFormatter):
by adding attributes to message arguments and coloring error
traceback.
"""
default_time_format = '%Y-%m-%d %H:%M:%S%z'
default_msec_format = None

def __init__(self, *args, **kwargs):
kwargs["stream"] = sys.stdout or kwargs.get("stream")
Expand Down
23 changes: 23 additions & 0 deletions airflow/utils/log/timezone_aware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import logging


class TimezoneAware(logging.Formatter):
default_time_format = '%Y-%m-%d %H:%M:%S%z'
default_msec_format = None
4 changes: 2 additions & 2 deletions airflow/www/static/js/ti_log.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function autoTailingLog(tryNumber, metadata = null, autoTailing = false) {

// Detect urls and log timestamps
const urlRegex = /http(s)?:\/\/[\w.-]+(\.?:[\w.-]+)*([/?#][\w\-._~:/?#[\]@!$&'()*+,;=.%]+)?/g;
const dateRegex = /\d{4}[./-]\d{2}[./-]\d{2} \d{2}:\d{2}:\d{2},\d{3}/g;
const dateRegex = /\d{4}[./-]\d{2}[./-]\d{2} \d{2}:\d{2}:\d{2}[+-]\d{4}/g;

res.message.forEach((item) => {
const logBlockElementId = `try-${tryNumber}-${item[0]}`;
Expand All @@ -120,7 +120,7 @@ function autoTailingLog(tryNumber, metadata = null, autoTailing = false) {
const escapedMessage = escapeHtml(item[1]);
const linkifiedMessage = escapedMessage
.replace(urlRegex, (url) => `<a href="${url}" target="_blank">${url}</a>`)
.replaceAll(dateRegex, (date) => `<time datetime="${date}+00:00" data-with-tz="true">${formatDateTime(`${date}+00:00`)}</time>`);
.replaceAll(dateRegex, (date) => `<time datetime="${date}" data-with-tz="true">${formatDateTime(`${date}`)}</time>`);
logBlock.innerHTML += `${linkifiedMessage}\n`;
});

Expand Down

0 comments on commit d589b9d

Please sign in to comment.