You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/09/28 20:31:07 UTC
[GitHub] ashb closed pull request #2442: [AIRFLOW-1412] Add config to
truncate the task log file
ashb closed pull request #2442: [AIRFLOW-1412] Add config to truncate the task log file
URL: https://github.com/apache/incubator-airflow/pull/2442
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py
index f568d5dc8e..9447112de0 100755
--- a/airflow/bin/cli.py
+++ b/airflow/bin/cli.py
@@ -457,6 +457,20 @@ def run(args, dag=None):
logging.root.handlers[0].flush()
logging.root.handlers = []
+ # truncate log files
+ max_log_file_size = conf.get('core', 'MAX_LOG_FILE_SIZE_BYTES')
+ if (
+ max_log_file_size and
+ os.path.exists(filename) and
+ os.path.getsize(filename) > int(max_log_file_size)
+ ):
+ command = 'truncate -s %s %s' % (max_log_file_size, filename)
+ try:
+ subprocess.check_call(command, shell=True)
+ except subprocess.CalledProcessError as e:
+ # don't fail the process just because log file truncate fails
+ logging.error(e)
+
# store logs remotely
remote_base = conf.get('core', 'REMOTE_BASE_LOG_FOLDER')
diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg
index ddd1ba816e..49a5c057e3 100644
--- a/airflow/config_templates/default_airflow.cfg
+++ b/airflow/config_templates/default_airflow.cfg
@@ -35,6 +35,9 @@ dags_folder = {AIRFLOW_HOME}/dags
# This path must be absolute
base_log_folder = {AIRFLOW_HOME}/logs
+# The max size of each task log file
+max_log_file_size_bytes =
+
# Airflow can store logs remotely in AWS S3 or Google Cloud Storage. Users
# must supply a remote location URL (starting with either 's3://...' or
# 'gs://...') and an Airflow connection id that provides access to the storage
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services