Redirecting console output to nicegui frontend #1663
FabianGoessling
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
This is an example of redirecting exceptions to a import traceback
from nicegui import app, ui
app.on_exception(lambda e: ui.notify(traceback.format_exception(e)))
def raise_exception():
raise Exception
ui.button('Raise Exception', on_click=raise_exception)
ui.run() |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thanks for sharing this, @FabianGoessling. It can indeed be very beneficial to view the full logs without needing to log into the host system! @natankeddem started a discussion about monitoring the nicegui.io website a few days ago: #1633 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I wanted to share a bit of my experience with nicegui so far.
Most of my scripts are standard synchronous python calls tied to an application object. This object does a log of logging or even printing, and of course sometimes unexpected exceptions.
Prior to adopting nicegui, keeping track of the logs either required to keep a console window open in addition to my frontend window (chrome/pywebview) or even inserting a grapqhlql endpoint in my FastAPI app via strawberry. The resulting stream can be subscribed to with some more JS code and finally the stream of messages can be consumed by a vue/vuetify component. Sounds like a lot of additional code? It surely is...
Using the log component and some tinkering, the below example shows how the full (?) console output can be redirected. Thus the console window can be hidden (pythonw.exe) and the native window makes the illusion of a "fully" native app complete.
Hopefully this is of use to anyone,
Greetings from Münster ;)
Beta Was this translation helpful? Give feedback.
All reactions