Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4F4AA200D2F for ; Wed, 18 Oct 2017 08:21:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4DC781609EC; Wed, 18 Oct 2017 06:21:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6ABD71609EB for ; Wed, 18 Oct 2017 08:21:29 +0200 (CEST) Received: (qmail 13760 invoked by uid 500); 18 Oct 2017 06:21:28 -0000 Mailing-List: contact dev-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list dev@airflow.incubator.apache.org Received: (qmail 13748 invoked by uid 99); 18 Oct 2017 06:21:28 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Oct 2017 06:21:28 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 5D3A41806FE for ; Wed, 18 Oct 2017 06:21:27 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.679 X-Spam-Level: X-Spam-Status: No, score=0.679 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id ERKcpuGLKimM for ; Wed, 18 Oct 2017 06:21:23 +0000 (UTC) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 06F385F3E3 for ; Wed, 18 Oct 2017 06:21:23 +0000 (UTC) Received: by mail-wm0-f47.google.com with SMTP id l68so7857863wmd.5 for ; Tue, 17 Oct 2017 23:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:date:subject:message-id :references:in-reply-to:to; bh=eOlx2olDtfqaDeq2bq+yW1a1M2f3QtsaIL7BMfvHnoo=; b=FSIqwItBTLJQkzYyClCLQkJIxtxeG/puNt1VVIrFAa6PV7SPVryffXQ/5p75gui5uv kYW1XD1ViJ9l6pcfNZTKump/EbY4Jy06AfGb/0aSY9d1ZTPmvWBjcatbEiJ5KVNyFDxE w6k68Iov4giklZbK48h3rAfM25iTsrumoANDw0pfv0yuoHIeEDpTk1OHm57vzM7rHLaT LFNap6VlF+pkGTRsDH00aJIZAHC4a/hISEM5IzSzA5MBMmtfV84VXvoN69PR842LGy5w 3MiWBBLaqlFFzS1ppOghpa7JnXZGjbjWeN2wl3X7bRlB4ujNmLpee7DvnkDM+r8uMESW ZcFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version:date :subject:message-id:references:in-reply-to:to; bh=eOlx2olDtfqaDeq2bq+yW1a1M2f3QtsaIL7BMfvHnoo=; b=t4tLG4eiH7Cl6mSWl3NeFF7BJT4a2EX+ixr8BKFrHRvUGDDy0DreIGGiC4ezclCdhM s9CaFA7k0MNPFsDN7Xm7xn/zTqYXqjy/le4behdROvUC7ZyUf/P6+zBLJ/NKZO8Jo/82 5IqWAeNyGLALHviToQqTC/TghwYsCfshdCfSSw25MxCQTuzKBKZF8h6C1SKsKF26nIbL BKyalJEPfTcihe0aG7Z3j9mjOy4Q09w2txuOsX3Cb4ojuFJKtobqrKHD8wstJ4MMacwz /hAWxmfporzp0WaeZtNuAILlUAL3+t7F9UxhJhOXEu9C2Gz8tb6HTHZ5iI2AYRvwcNEo 7bzQ== X-Gm-Message-State: AMCzsaUDoGwnzl5e3z1aGY3G5Dl2w7YnA/k40ji9ezO1VnnsEhVJ/khi oWkbITBr9dwISHtV1rd/R8IKB64KTkHS X-Google-Smtp-Source: ABhQp+T+emof3ViaKl35KE9ikFNhZx9YjuL4JZw/10t9upHB1ilW7rpBZznUirSCS2BiKsyFRFaR4Q== X-Received: by 10.80.174.152 with SMTP id e24mr170621edd.32.1508307681206; Tue, 17 Oct 2017 23:21:21 -0700 (PDT) Received: from [10.0.1.99] (f248061.upc-f.chello.nl. [80.56.248.61]) by smtp.gmail.com with ESMTPSA id e56sm8529869edb.72.2017.10.17.23.21.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Oct 2017 23:21:19 -0700 (PDT) From: Bolke de Bruin Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (1.0) Date: Wed, 18 Oct 2017 08:21:11 +0200 Subject: Re: new logging Message-Id: References: In-Reply-To: To: dev@airflow.incubator.apache.org X-Mailer: iPad Mail (15A421) archived-at: Wed, 18 Oct 2017 06:21:30 -0000 You should always init the logger. It is bad practice not to do it.=20 Log =3D logging.getLogger(__name__)=20 Is the canonical way. In Airflow we provide some convenience functions for o= perators etc. The loggingmixin can help out. Bolke Verstuurd vanaf mijn iPad > Op 17 okt. 2017 om 20:21 heeft Boris Tyukin het vo= lgende geschreven: >=20 > thank you both! so my understanding instead one liner like > logging.info("something") >=20 > I need to init logger first in a python operator and only after that I can= > invoke logger.info like below. This is a bit unexpected and a bit more wor= k > but it does work now - thanks. Maybe I was not doing it right in the first= > place but hey it did work in 1.8 :) >=20 > logger =3D logging.getLogger('airflow.python_test_logging') > logger.info('hi from loggin info') >=20 > On Tue, Oct 17, 2017 at 6:35 AM, Driesprong, Fokko > wrote: >=20 >> Hi Boris, >>=20 >> This is interesting. >>=20 >> When I run the example you provide with the latest Airflow release, I get= : >> root@9e3cf03c0544:~# airflow test python_test_logging print_the_context >> 2017-01-01 >> [2017-10-17 10:27:38,321] {__init__.py:45} INFO - Using executor >> SequentialExecutor >> [2017-10-17 10:27:38,359] {models.py:186} INFO - Filling up the DagBag fr= om >> /root/airflow/dags >> [2017-10-17 10:27:38,406] {dag.py:30} WARNING - test warn >> [2017-10-17 10:27:38,406] {dag.py:31} INFO - test info >> [2017-10-17 10:27:38,429] {models.py:1165} INFO - Dependencies all met fo= r >> > [None]> >> [2017-10-17 10:27:38,432] {models.py:1165} INFO - Dependencies all met fo= r >> > [None]> >> [2017-10-17 10:27:38,432] {models.py:1375} INFO - >> ------------------------------------------------------------ >> -------------------- >> Starting attempt 1 of 1 >> ------------------------------------------------------------ >> -------------------- >>=20 >> [2017-10-17 10:27:38,433] {models.py:1396} INFO - Executing >> on 2017-01-01 00:00:00 >> {'END_DATE': '2017-01-01', >> 'conf': > '/usr/local/lib/python3.6/site-packages/airflow/configuration.py'>, >> 'dag': , >> 'dag_run': None, >> 'ds_nodash': '20170101', >> 'end_date': '2017-01-01', >> 'execution_date': datetime.datetime(2017, 1, 1, 0, 0), >> 'latest_date': '2017-01-01', >> 'macros': > '/usr/local/lib/python3.6/site-packages/airflow/macros/__init__.py'>, >> 'next_execution_date': None, >> 'params': {}, >> 'prev_execution_date': None, >> 'run_id': None, >> 'tables': None, >> 'task': , >> 'task_instance': > 2017-01-01 00:00:00 [None]>, >> 'task_instance_key_str': >> 'python_test_logging__print_the_context__20170101', >> 'templates_dict': None, >> 'test_mode': True, >> 'ti': > 00:00:00 [None]>, >> 'tomorrow_ds': '2017-01-02', >> 'tomorrow_ds_nodash': '20170102', >> 'ts': '2017-01-01T00:00:00', >> 'ts_nodash': '20170101T000000', >> 'var': {'json': None, 'value': None}, >> 'yesterday_ds': '2016-12-31', >> 'yesterday_ds_nodash': '20161231'} >> hi from print >> [2017-10-17 10:27:38,441] {python_operator.py:90} INFO - Done. Returned >> value was: None >>=20 >> When I change it to `warn`, I do get: >> WARNING:root:hi from loggin info >>=20 >> =E2=80=8B=E2=80=8BBy giving an explicit logger, as Daniel suggested, that= starts with >> airflow%: >> def print_context(ds, **kwargs): >> pprint(kwargs) >> print('hi from print') >> logger =3D logging.getLogger('airflow.python_test_logging') >> logger.info('hi from loggin info') >>=20 >> =E2=80=8BThen it is picked up by the Airflow logging context=E2=80=8B: >> [2017-10-17 10:31:05,639] {dag.py:23} INFO - hi from loggin info >>=20 >> =E2=80=8BThis is how the current logging is set: >> https://github.com/apache/incubator-airflow/blob/master/ >> airflow/config_templates/airflow_local_settings.py >>=20 >> Currently I'm investigating why it used to work in Airflow 1.8. This is n= ot >> yet clear to me. >>=20 >> Cheers, Fokko=E2=80=8B >>=20 >>=20 >> 2017-10-17 7:58 GMT+02:00 Daniel Lamblin [Data Science & Platform Center]= < >> lamblin@coupang.com>: >>=20 >>> Boris, I don't see where you configured the default logger >>> . I >>> think >>> you'd have to at least throw in: >>> logger =3D logging.getLogger('python_test_logging') >>> and then use the logger.info(=E2=80=A6) instead of logging.info(=E2=80=A6= ) >>>=20 >>> On Tue, Oct 17, 2017 at 3:00 AM, Boris Tyukin >>> wrote: >>>=20 >>>> sorry i was not clear. >>>>=20 >>>> In DAG definition file, I would normally import logging and when use >> with >>>> python operator like below (see print_context). >>>>=20 >>>> In 1.8.2 i would see in Airflow log file (for that task) both 'hi from >>>> print' and 'hi from logging'. >>>>=20 >>>> now I can only see 'hi from print'. >>>>=20 >>>> I installed from master (pip install), and used newer airflow.cfg file.= >>>> Only updated it to use local executor and mysql db. Did not change any >>>> other settings. >>>>=20 >>>> So my question if it is supposed to work like that and how do I log now= >>>> from python operators in a dag. >>>>=20 >>>>=20 >>>> =EF=BB=BFfrom __future__ import print_function >>>> from builtins import range >>>> import airflow >>>> from airflow.operators.python_operator import PythonOperator >>>> from airflow.models import DAG >>>> import logging >>>> import time >>>> from pprint import pprint >>>>=20 >>>> args =3D { >>>> 'owner': 'airflow', >>>> 'start_date': airflow.utils.dates.days_ago(2) >>>> } >>>>=20 >>>> dag =3D DAG( >>>> dag_id=3D'python_test_logging', default_args=3Dargs, >>>> schedule_interval=3DNone) >>>>=20 >>>> def print_context(ds, **kwargs): >>>> pprint(kwargs) >>>> print('hi from print') >>>> logging.info('hi from loggin info') >>>>=20 >>>> run_this =3D PythonOperator( >>>> task_id=3D'print_the_context', >>>> provide_context=3DTrue, >>>> python_callable=3Dprint_context, >>>> dag=3Ddag) >>>>=20 >>>>=20 >>>> On Mon, Oct 16, 2017 at 1:09 PM, Driesprong, Fokko >> >>>=20 >>>> wrote: >>>>=20 >>>>> Hi Boris, >>>>>=20 >>>>> Can you please elaborate? Where did the output used to end up? Did >> you >>>>> provide any custom logging config, or are you using the default >> config? >>>>> Maybe drop some example code. >>>>>=20 >>>>> Cheers, Fokko >>>>>=20 >>>>> 2017-10-16 19:02 GMT+02:00 Boris : >>>>>=20 >>>>>> Hi guys, >>>>>>=20 >>>>>> I used to do logging.info("somthing") from airflow python >> operators >>>> so i >>>>>> can see output in airflow logs. Worked fine in 1.8.2. >>>>>>=20 >>>>>> Looks like this is no longer the case with master branch.I did look >>> at >>>>>> updating.md but still not clear how to log custom messages from >>> python >>>>>> operators. >>>>>>=20 >>>>>> please advise. >>>>>>=20 >>>>>=20 >>>>=20 >>>=20 >>>=20 >>>=20 >>> -- >>> -Daniel Lamblin >>>=20 >>=20