Skip to main content

How to Wrap Long Lines in a Task Log in the Apache Airflow® UI

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A long line in an Apache Airflow® task log stays on one row: its end is hidden past the right edge of the log, and you have to scroll sideways to read it. The log's Log Settings menu has a Wrap option that continues long lines on the next rows, so every line fits on screen. This guide wraps a long log line on Airflow 3.4.0.

The Example​

A Dag called long_log_line has one task, write_long_line, that writes a single long line to the task log: the sentence "This line is long." twenty times.

Prerequisites​

  • Apache Airflow® running, for example with airflow standalone, and its dags folder in your AIRFLOW_HOME.

Step 1: Write a Dag That Logs a Long Line​

Create dags/long_log_line.py:

dags/long_log_line.py
import logging

from airflow.sdk import dag, task

log = logging.getLogger(__name__)


@dag(schedule=None, tags=["demo"])
def long_log_line():
@task
def write_long_line():
log.info("This line is long. " * 20)

write_long_line()


long_log_line()

The long_log_line.py Dag file in an editor window: a logger from the logging module, and the write_long_line task that logs This line is long. repeated 20 times.

  • log is a logger from Python's logging module, and log.info(...) writes a line to the task log at the INFO level.
  • "This line is long. " * 20 repeats the sentence 20 times, so the task logs one line of 380 characters.

Step 2: Open the Task's Log​

Trigger the Dag and open the write_long_line task's log (How to Read a Task Log in the Apache Airflow® UI shows where to click):

The Logs tab of the write_long_line task: line 4, INFO - This line is long. repeated, runs to the right edge of the log and is cut off at This line i, above line 5, INFO - Done. Returned value was: None.

Line 4 stays on one row and is cut off at the right edge, in the middle of a word. The rest of it is still there: the log scrolls sideways, and in my check its content was 3,007 pixels wide in a box 1,136 pixels wide. When you scroll, the whole log moves, so the start of every line goes out of view.

Step 3: Turn On Wrap​

Above the log on the right, click Log Settings, the gear icon:

The Log Settings menu open under the gear icon above the log: Wrap with the key w, Hide Timestamps t, Hide Log Levels l, Expand e and Show Source s.

Click Wrap. The letter next to each item is its keyboard shortcut: pressing w while the log is open turns wrapping on or off without the menu.

The same log with wrapping on: line 4 continues on two more rows, so all twenty This line is long. sentences are visible, followed by line 5, INFO - Done. Returned value was: None.

Line 4 now continues on the next two rows, which start under its timestamp, and all twenty sentences are visible. It's still one log line: the number 4 appears once, and the next line is 5.

Step 4: Turn It Off Again​

With wrapping on, the menu's first item reads Unwrap. Click it, or press w again, and long lines go back to one row each.

Airflow remembers the choice in your browser. After a page reload the log stayed wrapped, and so did the logs of other Dags I opened later, until I turned wrapping off.

Common Mistakes​

MistakeWhat happensDo this instead
Scrolling sideways to read a long lineThe whole log moves, so the start of every line goes out of viewTurn on Wrap
Pressing w while the cursor is in the Search logs boxThe letter goes into the search box, and wrapping doesn't changeClick outside the box first, then press w

Troubleshooting​

SymptomLikely causeFix
Every log you open is wrappedWrapping was turned on earlier in the same browser, and Airflow kept the choice, or the [api] default_wrap setting is TrueClick Unwrap in Log Settings, or press w
Pressing w does nothingThe cursor is in a text box, such as Search logsClick outside the box, then press w

FAQ​

Does Wrap change the log itself?​

No. The choice is saved in your browser, not in Airflow, and it changes only how the page shows the log.

Can logs open wrapped without clicking Wrap first?​

Yes, in a browser that hasn't saved a choice yet. Airflow's [api] default_wrap setting is, in the configuration reference, the "Default setting for wrap toggle on DAG code and TI log views", and it's False unless you change it. I stopped Airflow and started it again with the setting turned on through its environment variable (How to Change the Port and Host of the Apache Airflow® API Server explains how these variables are named):

Terminal
export AIRFLOW__API__DEFAULT_WRAP=True
airflow standalone

In a browser with no saved choice, the log of write_long_line opened wrapped. A saved choice still wins: after I pressed w and reloaded the page, the log stayed unwrapped.

Conclusion​

write_long_line logged a line too long for the log, and it ran past the right edge. Wrap in the Log Settings menu, or the w key, continued it on the next rows, and Unwrap put it back on one row. Airflow remembers the choice in your browser, so one click keeps long lines readable in every log you open.

Additional Resources​

Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.