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():
    i=0
    while True:
        yield f"line {i} \n"
        i+=1

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

demo.queue.launch()