bellhea opened a new issue #10202: URL: https://github.com/apache/airflow/issues/10202
<!-- Welcome to Apache Airflow! For a smooth issue process, try to answer the following questions. Don't worry if they're not all applicable; just try to include what you can :-) If you need to include code snippets or logs, please put them in fenced code blocks. If they're super-long, please use the details tag like <details><summary>super-long log</summary> lots of stuff </details> Please delete these comment blocks before submitting the issue. --> <!-- IMPORTANT!!! PLEASE CHECK "SIMILAR TO X EXISTING ISSUES" OPTION IF VISIBLE NEXT TO "SUBMIT NEW ISSUE" BUTTON!!! PLEASE CHECK IF THIS ISSUE HAS BEEN REPORTED PREVIOUSLY USING SEARCH!!! Please complete the next sections or the issue will be closed. This questions are the first thing we need to know to understand the context. --> **Apache Airflow version**: 1.10.11 **Kubernetes version (if you are using kubernetes)** (use `kubectl version`): 1.10.0 **Environment**: - **Cloud provider or hardware configuration**: - **OS** (e.g. from /etc/os-release): rhel 7.7 - **Kernel** (e.g. `uname -a`): - **Install tools**: - **Others**: **What happened**: I'm trying to use the class [TaskHandlerWithCustomFormatter](https://github.com/kani5hk/airflow/blob/master/airflow/contrib/log/custom_file_task_handler.py). Since I am on version 1.10.11, this class is not yet available so I've copied the class and using it in my custom log_config.py. This is how I've used it: ``` import logging from logging import StreamHandler from airflow.utils.helpers import parse_template_string class TaskHandlerWithCustomFormatter(StreamHandler): def __init__(self, stream): super(TaskHandlerWithCustomFormatter, self).__init__() def set_context(self, ti): if ti.raw: return prefix = "TASK - {{ti.dag_id}}-{{ti.task_id}}-{{ds}}-{{try_number}}" rendered_prefix = "" if prefix: _, self.prefix_jinja_template = parse_template_string(prefix) rendered_prefix = self._render_prefix(ti) self.setFormatter(logging.Formatter(rendered_prefix + "TEST:" + self.formatter._fmt)) self.setLevel(self.level) def _render_prefix(self, ti): if self.prefix_jinja_template: jinja_context = ti.get_template_context() return self.prefix_jinja_template.render(**jinja_context) logging.warning("'task_log_prefix_template' is in invalid format, ignoring the variable value") return "" ``` ``` 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'formatter': 'airflow', 'stream': 'ext://sys.stdout' }, 'task_handler': { 'class': 'task_handler_with_custom_formatter.TaskHandlerWithCustomFormatter', 'formatter': 'airflow', 'stream': 'ext://sys.stdout' }, ... 'loggers': { 'airflow.processor': { 'handlers': ['processor', 'console'], 'level': LOG_LEVEL, 'propagate': False, }, 'airflow.task': { 'handlers': ['task_handler'], 'level': LOG_LEVEL, 'propagate': False, }, ``` I can see the prefix as I have defined in the logs, however the prefix is printed twice before the actual log text, e.g.: dag_id-task_id-2016-01-01-1:dag_id-task_id-2016-01-01-1:<LOG TEXT> Any ideas what could be wrong here? <!-- (please include exact error messages if you can) --> **What you expected to happen**: The prefix to only appear once <!-- What do you think went wrong? --> **How to reproduce it**: Code as above <!--- As minimally and precisely as possible. Keep in mind we do not have access to your cluster or dags. If you are using kubernetes, please attempt to recreate the issue using minikube or kind. ## Install minikube/kind - Minikube https://minikube.sigs.k8s.io/docs/start/ - Kind https://kind.sigs.k8s.io/docs/user/quick-start/ If this is a UI bug, please provide a screenshot of the bug or a link to a youtube video of the bug in action You can include images using the .md sytle of  To record a screencast, mac users can use QuickTime and then create an unlisted youtube video with the resulting .mov file. ---> **Anything else we need to know**: <!-- How often does this problem occur? Once? Every time etc? Any relevant logs to include? Put them here in side a detail tag: <details><summary>x.log</summary> lots of stuff </details> --> ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
