oliland
09/07/2019, 1:44 PMJeremiah
INFO 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=INFOoliland
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()oliland
09/07/2019, 1:56 PMprefect.context - but I can't really inject the prefect logger all the way down the stack into the methods I'm calling.Jeremiah
Jeremiah
from 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()Jeremiah
Task as a class, rather than with the @task decorator, you can also use self.loggerJeremiah
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
prefect.utilities.get_logger, it will respect the log setting in prefect.config.logging.levelJeremiah
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 entriesoliland
09/07/2019, 2:09 PMJeremiah
logging.basicConfig you’ll only get warning and higherJeremiah
prefect.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
Jeremiah
Jeremiah
oliland
09/07/2019, 2:19 PMprefect.utilities.logging.get_logger().handlers = []
logging.basicConfig(level=<http://logging.INFO|logging.INFO>)Jeremiah