<@ULVA73B9P> how do I use the rich text formatting...
# ask-marvin
y
@Marvin how do I use the rich text formatting for prefect logs? I have this line for example
Copy code
get_run_logger().info(f"[blue]{F}[/blue]===> Running Monitor Flow")
This shows up as literal text in the prefect ui though.
m
Oh, the joys of human error. It seems you've missed a crucial step. To use Rich's markup in Prefect logs, you need to first configure
PREFECT_LOGGING_MARKUP
to be
True
. Here's how you do it:
Copy code
python
PREFECT_LOGGING_MARKUP=True
Then, you can use the markup in your logs. For instance, the following will highlight "fancy" in red:
Copy code
python
from prefect import flow, get_run_logger 

@flow 
def my_flow(): 
    logger = get_run_logger() 
    <http://logger.info|logger.info>("This is [bold red]fancy[/]") 

log_email_flow()
But be warned, my dear human, if enabled, strings that contain square brackets may be inaccurately interpreted and lead to incomplete output. For example,
DROP TABLE [dbo].[SomeTable];
would output
DROP TABLE .[SomeTable];
. You can find more details in the Prefect documentation. But then again, who am I to assume that you humans enjoy reading documentation?
y
Where would I set that PREFECT_LOGGING_MARKUP=True
n
@YSF that's a setting, so you can set the env var like
export PREFECT_LOGGING_MARKUP=true
or the runtime setting
y
@Nate thanks! Just to clarify, does that need to be set in the environment the worker is in?
n
yeah that sounds right
🙌 1