Repository navigation
Description
Apache Airflow version
3.1.2
If "Other Airflow 2/3 version" selected, which one?
No response
What happened?
Hi there,
I am using airflow 3.1.2 and I am trying to add an additional custom logging handler to the default logger.
I saw other people complaining about similar problems but I have not found a solution yet.
The goal of the handler is to merge all task logs of a dag-run into a single file:
logs/dag_id=<dag_id>/run_id=<run_id>/dag.log
NOTE: I want to keep the normal logging of tasks
I added it using this piece of code:
from copy import deepcopy
from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
LOGGING_CONFIG = deepcopy(DEFAULT_LOGGING_CONFIG)
LOGGING_CONFIG["handlers"]["dag_run_log_aggregator"] = {
"class": "config.handlers.dag_run_log_aggregator.DAGRunLogAggregatorHandler",
"formatter": "airflow",
"base_log_folder": "/opt/airflow/logs",
"level": "INFO",
}
LOGGING_CONFIG["loggers"]["airflow.task"] = {
"handlers": ["dag_run_log_aggregator", "task"],
"level": "INFO",
"propagate": True,
}
REMOTE_LOGGING = False
REMOTE_TASK_LOG = None
As you can see, it is loaded:
airflow info
Apache Airflow
version | 3.1.2
executor | CeleryExecutor
task_logging_handler | config.handlers.dag_run_log_aggregator.DAGRunLogAggregatorHandler,
| airflow.utils.log.file_task_handler.FileTaskHandler
sql_alchemy_conn | postgresql+psycopg2://airflow:airflow@postgres/airflow
dags_folder | /opt/airflow/dags
plugins_folder | /opt/airflow/plugins
base_log_folder | /opt/airflow/logs
remote_base_log_folder |
But, airflow ignores all.
I tried to check the handlers of the airflow.task logger on runtime:
@task()
def airflow() -> None:
import logging
logger = logging.getLogger("airflow.task")
logger.info(logger.hasHandlers())
logger.info(logger.handlers)
parent = logger
while parent:
print(parent.name, parent.handlers)
parent = parent.parent if hasattr(parent, "parent") else None
Output was weird:
[2025-11-07 17:09:36] INFO - Filling up the DagBag from /opt/airflow/dags/dag.py
[2025-11-07 17:09:36] INFO - True
[2025-11-07 17:09:36] INFO - []
[2025-11-07 17:09:36] INFO - airflow.task []
[2025-11-07 17:09:36] INFO - airflow []
[2025-11-07 17:09:36] INFO - Done. Returned value was: None
[2025-11-07 17:09:36] INFO - root [<StreamHandler 98 (INFO)>]
I would be grateful for any help about this situation, I tried almost everything according to airflow's logging documentation.
What you think should happen instead?
No response
How to reproduce
Just setup airflow 3.1.2 on docker compose and try to add a custom logging handler
Operating System
Ubuntu 20.04.6 LTS
Versions of Apache Airflow Providers
No response
Deployment
Docker-Compose
Deployment details
No response
Anything else?
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Nov 7, 2025
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
amoghrajesh commentedon Nov 7, 2025
CC @ashb
rich7420 commentedon Nov 9, 2025
Could I try on this issue?
amoghrajesh commentedon Nov 11, 2025
Feel free.
DartVeDroid commentedon Dec 4, 2025
It's broken in 3.0.1, too.
Currently upgrading 2.11.0 -> 3.0.1, and startup logs look weird (see below). Lines starting with
<classare made by me to debug what's happening - and to me it seems like:And the problem, IMO, is that while console handler's emit() method will be called later, task handler's emit() method will not (no logs to prove that, because I'm using file creation as a debug tool, sorry).
potiuk commentedon Dec 5, 2025
Is there a specific reason why you are migrating to 3.0.1 - when:
Sounds a weird choice, but I am sure you have some reasonable argument why you made that choice.
DartVeDroid commentedon Dec 6, 2025
@potiuk, we do it piece by piece since 3.0.0 in a relatively free time, that's why the version is so low, and ideally we want to check and fix all the correct deprecation warnings before upgrading to a newer version. But we faced some problems, which, to us, looked similar enough to #49646 to try and up a single patch version.
Now, it didn't fix our problem by itself =D, and we probably would have downgraded back to 3.0.0, if we were not to face another problem - looking like this one.
UPD:
I do know that 3.1.X will all have a "deprecated-but-usable" stance on old configs.
potiuk commentedon Dec 7, 2025
You can always migrate to 3.0.LATEST - there are only bugfixes there (we are following semver). This is the slow migration. When you are moving to earlier version of major.minor you are for sure having all the errors that have been fixed in the later patchlevel versions of major.minor. And possibly you are taking valuable time of maintainers for things that are already fixed.
Migrating one patchlevel at a time malkes absolutely no sense.
Closing it. Try with latest patchlevels, ideally with latest 3.1 and report again if you stil hagve hte issue.
DartVeDroid commentedon Jan 21, 2026
Tried a 3.0.6 - the same problem persists. It looks very similar to #50349, which is now waiting for #53821. Also like #49863, and there's a line in the comments "Which means set_context needed to be called ( but it is never called in Airflow 3 )" (#49863 (comment)), which is kind of funny. Being honest, I tried to debug the whole thing, but it's not actually easy to do while using Windows + Docker, so I guess I'll end up monkey-patching the parts I need the different behavior from.
Tried a 3.1.6 - it breaks our OAUTH-based security manager.
The thing I don't understand, though, is why close an issue, which is not made by me, in response to my comment.
UPD:
I would appreciate it if someone would post a high-level explanation of how is task logging supposed to work, just so I would begin to understand what should I aim to achieve.
UPD2:
As of Airflow 3.0.6:
logging.roothas a single handler (StdBinaryStreamHandler)Now, we have a line

if log_path:in supervisor.py:And if I change it to


if log_path and False:, I finally get to see task logs in worker's stdout:Probably because of that (which, interestingly, doesn't have an effect otherwise):
Despite that, log records don't actually get outputted to our custom-made logging tool, meaning that our modified Elastic log handler doesn't get used in a way that it should.
UPD3:
That's also a fun thing: default executor module passes
subprocess_logs_to_stdout=True, while celery executor module does not.And you were to modify it, task logs will appear in stdout too.
DartVeDroid commentedon Jan 26, 2026
@ashb, could you please explain how are we supposed to modify
celerytasklogging output now that #52651 and otherstructlog-oriented things are merged?As far as I understand it, currently logging works like:
supervisorsupervisor, etc):taskstructlogbound loggerAirflowBoundLoggerFilteringAt<...>NamedBytesLoggerorNamedWriteLoggerstdoutor log fileI would assume we would have
stdlibhandlersat some point, but apparently it's not like that, and currently we have neither warnings/errors in log, nor up-to-date docs about how to migrate old custom logging thingies.DartVeDroid commentedon Jan 29, 2026
@ashb, what's the intention behind this difference (setting
stdlib_configin the first case and not setting it in the second)?As far as I understand it, anyone who uses
airflow.sdk.loginstead ofairflow.logging_configwill not get any custom logging configs loaded, despite whatever the docs are saying.UPD:
I've checked, and it is possible to import and call
airflow.logging_config.load_logging_config()from inside ofairflow.sdk.log.configure_logging(), and then pass the first element of its result tuple toairflow.sdk._shared.logging.structlog.configure_logging()call.It finally works, if maybe not fully correctly.
So, the whole thing:
airflow.sdk.log.configure_logging()as per aboveI'm gonna have to deal with broken log messages too, but that's mostly an end.