Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pserve out function always prints to stderr #3710

Open
markonose opened this issue Sep 29, 2022 · 3 comments
Open

pserve out function always prints to stderr #3710

markonose opened this issue Sep 29, 2022 · 3 comments

Comments

@markonose
Copy link

markonose commented Sep 29, 2022

In https://github.com/Pylons/pyramid/blob/master/src/pyramid/scripts/pserve.py#L146

The script outputs everything to the stderr file descriptor. If you redirect the stdout and stderr stream to your logger, then for example the 'Starting server' message gets logged as an error.

I would propose to split the out function into two in PServeCommand:

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

    def out_err(self, msg):  # pragma: no cover
        if self.args.verbose > 0:
            print(msg, file=sys.stderr)

And call the out_err function to print 'You must give a config file'.

In the rest of the file all of the other prints could also be changed to stdout, so that hey would no longer output starting/serving messages to stderr.

In other scripts even errors get printed to stdout, so this could also be applied in other scripts where applicable: https://github.com/Pylons/pyramid/blob/master/src/pyramid/scripts/prequest.py#L135

I can create a PR if such a changes would be permitted.

@mmerickel
Copy link
Member

It's standard practice that logging systems log to stderr and leave stdout for core functionality. In the case of pserve everything is logging, leaving the core functionality to the wsgi server itself. I'm not sure this is really incorrect.

I would argue that prequest should be outputting several of those messages to stderr and could use some updates there.

@markonose
Copy link
Author

markonose commented Sep 29, 2022

Thank you for the quick reply.

Sorry my bad did not realize that it was standard practice to also output diagnostic data to stderr.

The idea behind my question was because we use pyramid with pserve, and in our app we redirect the stderr to our logger, in case something would go wrong it would get logged as an error. But after inspecting the code more closely, I can see that the only error 'You must give a config file' would get printed before the app even gets created, so it wouldn't get logged. So this was not really needed on our part.

Regarding prequest the error output should then be written to stderr and not stdout to keep things consistent. I would be happy to go through all of the commands and change the outputs to the correct stream if needed.

@mmerickel
Copy link
Member

I think that'd be great if you wanted to do that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants