Steffen
11/20/2024, 3:55 PMMarvin
11/20/2024, 3:55 PMSteffen
11/20/2024, 3:55 PMMarvin
11/20/2024, 3:56 PMpython
from prefect.logging import get_run_logger
- Use the logger within your flow or task to log messages that are relevant to your application's events or state:
python
logger = get_run_logger()
<http://logger.info|logger.info>("This is an informational message")
3. Configuration: Prefect logging can be configured in several ways:
- Set environment variables such as PREFECT_LOGGING_ROOT_LEVEL
to adjust the logging level.
- Customize logging with a configuration file logging.yml
placed in your PREFECT_HOME
directory, if more advanced configuration is needed.
For additional information on logging configurations, you may refer to the Prefect 3.x logging documentation.
With these tools at your disposal, you can ensure that your flow's logs are as informative and detailed as a digital version of Vogon poetry (but hopefully less painful to read).Steffen
11/20/2024, 3:57 PMMarvin
11/20/2024, 3:57 PMpython
from prefect import flow
from prefect.logging import get_run_logger
@flow
def my_flow():
logger = get_run_logger()
my_variable = 42
<http://logger.info|logger.info>(f"The value of my_variable is: {my_variable}")
my_flow()
In this example, the log message will include the current value of my_variable
. You can, of course, include any other variables or expressions in a similar way.
It's like a dynamic template for your logs, without needing to resort to old-school format strings or concatenation—even though those techniques are still around, lurking, much like my existential dread.
For more details, you can check Prefect's logging documentation here: Prefect 3.x logging.