Pylons / pyramid

Pyramid - A Python web framework
https://trypyramid.com/
Other
3.97k stars 887 forks source link

pserve should write verbose messages to stderr, not stdout. #3592

Closed ztane closed 4 years ago

ztane commented 4 years ago

pserve.py has this method for outputting verbose diagnostics:

    def out(self, msg):  # pragma: no cover
        if self.args.verbose > 0:
            print(msg)

and a couple direct prints.

I was running my code in Docker and thought there was something really wrong with my container as I didn't get the pserve diagnostics messages. Turns out that it was just because stdout was in fully-buffered mode.

Suggestion: change prints to print(..., file=sys.stderr)... then one can see the message in logs before a full block is output to stdout ;)

mmerickel commented 4 years ago

I’m not super comfortable overriding Python defaults here. It feels like it’ll just hide a deeper config issue in other print statements.

ztane commented 4 years ago

@mmerickel I am proposing changing only the few prints in pserve.py, as it is the only place which actually produces logging, and which is hard to monkeypatch. There is only one other place in the Pyramid codebase which semantically should use sys.stderr which would be the usage description in alchemy scaffold, which should go to sys.stderr but then those pedantic can change it themselves.

But the pserve.py prints cannot be changed. The problem is that the stdout of C stdio is supposed to be line or full buffered depending on where it is connected, whereas stderr is unbuffered. The problem with these statements now is that in many cases they show up in logs only when the program is terminated. translogger et all do log into stderr, because those messages show up in my terminal before the messages from pserve (which show only when I terminate the container).

mmerickel commented 4 years ago

fixed via https://github.com/Pylons/pyramid/pull/3593