Print log in web UI

If I use textbox or textarea as output,
the log will show when the progress finished.
if the result has some error, might just show a err
so how to print log real-time in web UI?

I am new to gradio but a possible solution could be by using generators and queues like following:

import gradio as gr

def gen_logs():
    while True:
        yield f"line {i} \n"

with gr.Blocks as demo:
    test_textbox = gr.Textbox(lines=8)
    test_btn = gr.Button(value="show logs"),inputs=[],outputs=test_textbox)