Pylons / waitress

Waitress - A WSGI server for Python 3
https://docs.pylonsproject.org/projects/waitress/en/latest/
Other
1.45k stars 176 forks source link

Use log_info instead of print in print_listen #315

Closed lstolcman closed 4 years ago

lstolcman commented 4 years ago

The problem:

I would like to catch "Serving on...." message using python logging module and process it later in my appllication. https://github.com/Pylons/waitress/blob/e2adf082e6942ee785bbc447beaa2c4d9764893f/src/waitress/__init__.py#L15 Currently, it outputs to stdout and could not be handled by logging system.

Solution: replace print with log_info (a wrapper for logging module)

Merging it before releasing 2.0 would help me a lot

Connected with https://github.com/Pylons/waitress/issues/133

digitalresistor commented 4 years ago

What if someone doesn't have the logging subsystem configured correctly? waitress does not assume that Python logging has been configured.

Does the default root logger output info logs?

What problem are you trying to solve for by capturing the output?

lstolcman commented 4 years ago

What if someone doesn't have the logging subsystem configured correctly? waitress does not assume that Python logging has been configured.

It does: https://github.com/Pylons/waitress/blob/e2adf082e6942ee785bbc447beaa2c4d9764893f/src/waitress/__init__.py#L12

Does the default root logger output info logs?

Yes: https://docs.python.org/3/library/logging.html#logging.basicConfig https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler

What problem are you trying to solve for by capturing the output?

"I would like to catch "Serving on...." message using python logging module and process it later in my appllication."

digitalresistor commented 4 years ago

Merge and or rebase master into this and make sure all the tests pass please.

mmerickel commented 4 years ago

@lstolcman nudge, did you see bert's request above?

lstolcman commented 4 years ago

@mmerickel @bertjwregeer done

sr-gi commented 4 years ago

Not sure if this is the best place to comment given the PR has already been merged, but didn't know if it was worth opening an issue for this:

Looks like this was not applied for the MultiSocketServer, but only for BaseWSGIServer. Creating an instance of a MultiSocketServer will still use print instead of self.log_info.

stevepiercy commented 4 years ago

@sr-gi would you please create a new issue, reference this one, and submit a PR with the proposed fix? I am pretty sure it will be accepted.

lstolcman commented 4 years ago

@sr-gi

Looks like this was not applied for the MultiSocketServer, but only for BaseWSGIServer. Creating an instance of a MultiSocketServer will still use print instead of self.log_info.

Yeah, I only covered my use-case. I saw the print for MultiSocketServer, but did not fixed that to use logging, because I do not use that class. IMO if you'll replace the print with log_info, it should simply work