In airflow it's possible to write to the log with a simple print()
or with logger as suggested here
However this won't work when trying to print inside an operator.
I have the following code:
for i in range(5, 0, -1):
gcs_export_uri_template = ["adstest/{{ macros.ds_format(macros.ds_add(ds, -params.i), '%Y-%m-%d', '%Y/%m/%d') }}/*"]
update_bigquery = GoogleCloudStorageToBigQueryOperator(
dag=dag,
task_id='load_ads_to_BigQuery-{}'.format(i),
bucket=GCS_BUCKET_ID,
destination_project_dataset_table=table_name_template,
source_format='CSV',
source_objects=gcs_export_uri_template,
schema_fields=dc(),
params={'i': i},
create_disposition='CREATE_IF_NEEDED',
write_disposition='WRITE_APPEND',
skip_leading_rows=1,
google_cloud_storage_conn_id=CONNECTION_ID,
bigquery_conn_id=CONNECTION_ID
)
Now say I want to print "My name is load_ads_to_BigQuery-{}".format{i)
as you can see this print is uniuqe per operator.
If I do it as:
for i in range(5, 0, -1):
print("My name is load_ads_to_BigQuery-{}".format{i))
gcs_export_uri_template = ...
update_bigquery = GoogleCloudStorageToBigQueryOperator(...)
All 5 operators will print all 5 prints. Which is incorrect in my case.
The print must be inside the GoogleCloudStorageToBigQueryOperator
.
How can I do that?