Hey everyone! I'm trying to log some parameter in ...
# ask-community
j
Hey everyone! I'm trying to log some parameter in a prefect flow. After launching a quick run, I can't find any mention of my log on cloud. It looks a bit like this:
Copy code
@task
def extract_copy_history(cursor, schema_table):
  logger = prefect.context.get("logger")
  <http://logger.info|logger.info>(f"Schema table name is {schema_table}.")
Now when I do a quick run on Prefect Cloud, no mention of it appears in my logs despite it being set on "Showing logs for all log levels". I see the log for the task in itself (extract_copy_history) and all other tasks. Just not my custom log.
k
Hi @Jérémy Trudel! Is this a normal Python function or did you decorate it with
@task
?
j
I decorated it with a task! Yeah I'll edit it with it
k
This seems good do me. Do you have a minimum working example?
j
Yes I can send you what the logs look like privately
k
If the flow is quick to run, can you try changing
<http://logger.info|logger.info>
to a higher level like
logger.warning
. Can you also try the same thing and log another task with some message?
j
Yes I'll try that
k
“Showing all log levels” in the UI is because you can filter the ones you want to look at there. It doesn’t mean that all levels of logs were outputted
j
Tried warning and same story
Oh I forgot an important part: the task is a mapped task
k
I see. Does logging work for your non mapped tasks?
j
Looks like this:
Copy code
errors = extract_copy_history.map(cursor=unmapped(cursor), schema_table=tables)
I'll try it right now
Logging does work for my non-mapped tasks
k
Logging for your non-mapped tasks was set as INFO? I tried logging on mapped tasks and it worked. Let me try doing it with an
unmapped
Could you try a simple flow:
Copy code
import prefect
from prefect import Flow, task, unmapped

@task
def get_numbers():
    logger = prefect.context.get("logger")
    <http://logger.info|logger.info>(f"Testing the log.")
    return [1,2,3]

@task
def plus_one(constant,x):
    logger = prefect.context.get("logger")
    <http://logger.info|logger.info>(f"Mapped logger value {x}")
    return x+constant

with Flow('logging-flow') as flow:
    n = get_numbers()
    plus_one.map(constant = unmapped(1), x = n)

flow.run()
j
I just realized the problem was that I was mapping on an empty parameter 😰 that's why I had no logs. Sorry abotu that and thank you for your help!
k
Wow I hope that wasn’t too painful to find! All good. Happy to help 🙂