Ashe
05/18/2023, 2:40 PMdef get_logger(name):
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG) # Or any level you want
# Create a console handler
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) # 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
Nate
05/18/2023, 3:40 PMPREFECT_LOGGING_SETTINGS_PATH=PosixPath('${PREFECT_HOME}/logging.yml')
❯ ipython
Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:25:12) [Clang 14.0.6 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import prefect
10:42:05.186 | DEBUG | prefect.profiles - Using profile 'pong'
In [2]: prefect.settings.get_current_settings() # and ctrl-F for "log"
Robert Banick
05/18/2023, 4:05 PMAPILogHandler
to your logger — this will pipe its outputs to the UI just like a run_logger
.
from prefect.logging.handlers import APILogHandler
def get_logger(name):
# your code
api_handler = APILogHandler()
logger.addHandler(api_handler)
return logger
Ashe
05/22/2023, 3:58 PMRobert Banick
05/22/2023, 3:59 PMAshe
05/22/2023, 4:00 PMget_logger
is global for me, when I’m not running a flow and testing other parts of the code base locally I get
attempted to send logs to the API without a flow run id. The API log handler can only send logs within flow run contexts unless the flow run id is manually provided.
wondering if you found a clever way to only add this handler when it knows its a “flow”Robert Banick
05/22/2023, 5:10 PMNate
05/22/2023, 5:49 PM