0

I want to use an existing (big) python app (let's call it my_backend.py) with a web browser. For that, I've added a small python file using flask (+ templates/index.html).

It's work...but now I'd like to redirect all the messages from the logging module.

Typical simple use case:

in my_backend.py:

logger.info("Hello world")
logger.error("Error found !")

in the web browser, the user should see these messages.

Is there somewhere a (very) simple example including the python code and according HTML page ? The idea is to not modify the backend python code.

Additional (post) note: see comments below...The need has to be reconsidered.

Related resources or links: Display data streamed from a Flask view as it updates

Dominique
  • 1
  • 3
  • unless You use javascript, users will have to reload the page to see any changes, otherwise very doable, all You really have to do is to define some function (not necessary to make a new one, but it is better IMO) that will simply open that file, read the last lines or sth, then return those lines, this function gets executed every time the route is called and the returned value is passed into the html template, but again, the user will have to reload the page (also now thinking about this - can two processes access the same file simultaneously if that would be the case?) – Matiiss Jul 20 '21 at 09:54
  • yes, you're right. It's not simple as I'd like to implement a "solution" for the user. By the way, the backend app takes time (a few minutes) and most of the logging messages are interesting for the user(s). So, yes, additional functions have to be implemented, filtering the previous/current log messages. For example something based on the _yield_ statement (as [here](https://stackoverflow.com/questions/31948285/display-data-streamed-from-a-flask-view-as-it-updates?noredirect=1&lq=1)) – Dominique Jul 20 '21 at 10:20
  • ok, I didn't get what You were trying to tell me, but ok, good luck, also to mention that on SO You should kinda more of show Your attempts and tell what is wrong with Your existing code (which is not the case here), anyhow I see that You found what You wanted apparently (actually it probably will be useful for me too so thanks) – Matiiss Jul 20 '21 at 10:25

0 Answers0