Hi, Can someone please help me to suppress INFO l...
# ask-community
s
Hi, Can someone please help me to suppress INFO level logs while running the flow, I tried
run_config
while building the flow, but it seems not working.
1
e
Are you running with prefect server/cloud, or are you using
flow.run()
?
run_config
is for registering a flow to prefect server or cloud, I don't think it would effect a run triggered by
flow.run()
s
Oh okay, I am actually running using
flow.run()
. Do you know how to suppress logs in this case?
g
https://docs.prefect.io/core/concepts/logging.html#logging-configuration either set
prefect.config.logging.level
to
WARN
(or whatever) in your code, or change the environment variable
PREFECT__LOGGING__LEVEL
in the env where you're executing
flow.run()
👍 1
s
I tried that
prefect.config.logging.level=DEBUG
. it is not working.
g
If you set the logging level as
DEBUG
then all messages of all severity will be shown. If you want to suppress messages, you need to set the logging level at a higher level than the messages you want to see.
s
okay, let me check.
It is not working, tried both ways setting
prefect.config.logging.level=ERROR
and
os.environ["PREFECT__LOGGING__LEVEL"] = "ERROR"
Okay, it is finally worked. had to set environment variable before
os.environ["PREFECT__LOGGING__LEVEL"] = "ERROR"
before importing prefect as I read in some other thread in this forum, but still there is no run level control. Ideally I would want to pass it as argument in
flow.run()
whether to print logs or not.
e
Found something that can be useful: Papa logger for prefect is stored under
prefect.utilities.logging.prefect_logger
, all other loggers of prefect are children to this logger. using setLevel on this can act as a run level control. This worked on my try.
Copy code
prefect.utilities.logging.prefect_logger.setLevel("ERROR")
Looks hacky, but I can't think of anything else. Also I lack experience on logging module, so there might be better ways to do this, idk.
👍 1
Also, this is probably why your solution only works before importing. the global object
prefect_logger
is initialized within
import prefect
👍 2