oliland
09/07/2019, 1:44 PMJeremiah
09/07/2019, 1:52 PMINFO
messages by default, as you can see here: https://github.com/PrefectHQ/prefect/blob/master/src/prefect/config.toml#L26. If you need to change this directly, you can set the environment variable PREFECT__LOGGING__LEVEL=INFO
oliland
09/07/2019, 1:53 PMlogger = logging.getLogger(__name__)
@task(name="Test logging")
def test_logging():
<http://logger.info|logger.info>("Hidden by default")
logger.warning("Shown by default")
with Flow("test") as flow:
test_logging()
flow.run()
prefect.context
- but I can't really inject the prefect logger all the way down the stack into the methods I'm calling.Jeremiah
09/07/2019, 1:56 PMfrom prefect import task, Flow
import prefect.utilities
logger = prefect.utilities.logging.get_logger(__name__)
@task(name="Test logging")
def test_logging():
<http://logger.info|logger.info>("Hidden by default")
logger.warning("Shown by default")
with Flow("test") as flow:
test_logging()
flow.run()
Task
as a class, rather than with the @task
decorator, you can also use self.logger
oliland
09/07/2019, 2:03 PMimport mypackage
@task(name="Test logging")
def test_logging():
my_package.run()
with Flow("test") as flow:
test_logging()
flow.run()
with this setup, the prefect logger spits out WARNING
messages from mypackage
- but not INFO
messages. How can I change that?Jeremiah
09/07/2019, 2:06 PMprefect.utilities.get_logger
, it will respect the log setting in prefect.config.logging.level
oliland
09/07/2019, 2:08 PMlogging.basicConfig(level=<http://logging.INFO|logging.INFO>)
solves this issue for me, but it means I get double log entriesJeremiah
09/07/2019, 2:09 PMlogging.basicConfig
you’ll only get warning and higherprefect.utilities.logging.get_logger()
and set its handlers
attribute to []
. I don’t think we expose a first-class way to disable them right nowoliland
09/07/2019, 2:12 PMbasicConfig
myself - so I guess I'm just missing a way to change the defaultJeremiah
09/07/2019, 2:12 PMoliland
09/07/2019, 2:19 PMprefect.utilities.logging.get_logger().handlers = []
logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
Jeremiah
09/07/2019, 2:22 PM