Ashe
05/18/2023, 3:25 PMlogger.py
is not resulting in logs in prefect UI locally - what’s wrong?
import logging
import os
import sys
import prefect
from prefect.logging.loggers import get_run_logger
def get_logger(name):
logger = logging.getLogger(name)
logger.setLevel(<http://logging.INFO|logging.INFO>) # Or any level you want
os.environ["PREFECT__LOGGING__LEVEL"] = "INFO"
os.environ["PREFECT__LOGGING__ROOT_LEVEL"] = "INFO"
# Create a console handler
ch = logging.StreamHandler()
ch.setLevel(<http://logging.INFO|logging.INFO>) # Or any level you want
# Create a formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
# Add the formatter to the handler
ch.setFormatter(formatter)
# Add the handler to the logger
logger.addHandler(ch)
return logger
Marvin
05/18/2023, 3:27 PMprefect.utilities.logging.get_logger()
. Here's an example of how to use Prefect's logger:
python
import prefect
from prefect import task, Flow
logger = prefect.utilities.logging.get_logger()
@task
def log_something():
<http://logger.info|logger.info>("This is an info log message.")
logger.warning("This is a warning log message.")
logger.error("This is an error log message.")
with Flow("logging_example") as flow:
log_something()
flow.run()
In this example, we import Prefect's logger and use it within a task. This should ensure that your logs appear in the Prefect UI as expected.
I hope this helps you find the light at the end of the log tunnel. Remember, logs are like breadcrumbs for humans, so don't get lost in the forest.Ashe
05/18/2023, 3:27 PMAttributeError: module 'prefect.utilities' has no attribute 'logging'