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

http: serve() should log where it is listening #1641

Merged
merged 4 commits into from
Apr 22, 2022
Merged

http: serve() should log where it is listening #1641

merged 4 commits into from
Apr 22, 2022

Conversation

ry
Copy link
Member

@ry ry commented Nov 28, 2021

reduces boilerplate in examples https://deno.com/deploy/docs/examples

@ry ry requested review from bartlomieju and kt3k as code owners November 28, 2021 14:16
Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an option to disable this log message.

http/server.ts Outdated
const server = new Server({ addr, handler });

if (options?.signal) {
options.signal.onabort = () => server.close();
}

console.log(`Listening on http://${addr}/`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use the resolved address, rather than the original address.

@ry
Copy link
Member Author

ry commented Nov 28, 2021

people can use listenAndServe if they don't want the log message. This is a convenience function.

@kt3k
Copy link
Member

kt3k commented Dec 2, 2021

@ry

people can use listenAndServe if they don't want the log message. This is a convenience function.

I like the idea. So in that case we cancel the deprecation of listenAndServe and recommend it for more customized use cases?

@vwkd
Copy link
Contributor

vwkd commented Dec 8, 2021

Is there a precedence for including logging in a std module? This change implicitly assumes that the console is the right place to log. Std has a whole logging framework std/log because that might not be the case. Also what if you want a different log message, e.g. add your application name, log levels, etc. pp.? Baking a log message into the std module makes all of this impossible. What if you want no logging? Need to use an option or even another function to turn logging off? Imagine for a second this logging by default is true throughout the whole std library… Yikes!

Also the motivating Deno Deploy examples should probably instead delete the “Listening on http://localhost:” logs because this URL makes sense only when running locally with Deno CLI, not when running on Deno Deploy, which has a different URL (not localhost!) and ignores the port. A much better place would be a note in the documentation on “Running locally” using the Deno CLI, mentioning that serve can be given any port (defaulting to 8000 if none is given) because Deno Deploy doesn’t use it.

It seems to me a rather thoughtless optimization to reduce a given example code by 1 LOC. I advise to carefully reconsider this.

@kt3k
Copy link
Member

kt3k commented Dec 18, 2021

Having thought about this again, I now feel it's not worth providing 2 different APIs with such subtle difference.

If we have more features to add to the 'convenient' API, then that might worth it. However if the logging of that line is the only difference, I don't think it's worth it..

@kt3k
Copy link
Member

kt3k commented Apr 21, 2022

Reconsidered this again. console.log("Listening ...") is actually a boilerplate for almost 100% cases of the usages. I think this change is worth trying.

@ry ry merged commit 3b7aca1 into main Apr 22, 2022
@ry ry deleted the server-log branch April 22, 2022 20:15
@mashaal
Copy link

mashaal commented May 1, 2022

people can use listenAndServe if they don't want the log message. This is a convenience function.

@ry @kt3k - Is listenAndServe still the recommended way to get around this log? We have tested it's usage, and it seems to work as intended, but it's still marked as deprecated?

https://deno.land/std@0.137.0/http/server.ts#L630

@kt3k
Copy link
Member

kt3k commented May 1, 2022

@mashaal

@ry @kt3k - Is listenAndServe still the recommended way to get around this log?

Honestly I'm not sure. Canceling the deprecation of listenAndServe is one option. Adding some option for disabling logging might be another option. Do you have any opinion on this?

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

Successfully merging this pull request may close these issues.

5 participants