Repository: cloudwego/hertz (go)

Issue:
optimize: add a option to controls whether debugPrintRoute executes
**Is your feature request related to a problem? Please describe.**

-  When the server is running, it  will print a lot of logs of the routes and i wish I could control its printing

**Describe the solution you'd like**

- add a option


Pull request description:
optimize: add a option to controls whether debugPrintRoute executes
#### What type of PR is this?

optimize
<!--
Add one of the following kinds:

build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
docs: Documentation only changes
feat: A new feature
optimize: A new optimization
fix: A bug fix
perf: A code change that improves performance
refactor: A code change that neither fixes a bug nor adds a feature
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc)
test: Adding missing tests or correcting existing tests
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
-->

#### Check the PR title.
<!--
The description of the title will be attached in Release Notes, 
so please describe it from user-oriented, what this PR does / why we need it.
Please check your PR title with the below requirements:
-->
- [x] This PR title match the format: \<type\>(optional scope): \<description\>
- [x] The description of this PR title is user-oriented and clear enough for others to understand.


#### (Optional) Translate the PR title into Chinese.

添加一个选项来控制是否执行 `debugPrintRoute`

#### (Optional) More detail description for this PR(en: English/zh: Chinese).
<!--
Provide more detailed info for review. If it is a perf type PR, perf data is suggested to give.
-->

en: Added an option to control whether to print the route's log when it starts running, the default is to print. If **panic** occurs when there are many routes, because there is a lot of routing startup information, **panic** cannot be seen intuitively. Adding this option can avoid such a situation.

zh(optional): 新增了一个可选项来控制是否在开始运行时打印路由的日志，默认为打印。在路由较多时若发生**panic**，由于有大量的路由启动信息，因此不能直观的看到**panic**，增加此可选项后可避免此类情况出现。

#### Which issue(s) this PR fixes:
<!--
Automatically closes linked issue when PR is merged.
Eg: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #268 


Patch:
diff --git a/pkg/app/server/option.go b/pkg/app/server/option.go
index ccfa97a..fc913e4 100644
--- a/pkg/app/server/option.go
+++ b/pkg/app/server/option.go
@@ -288,3 +288,11 @@ func WithAutoReloadRender(b bool, interval time.Duration) config.Option {
 		o.AutoReloadInterval = interval
 	}}
 }
+
+// WithDisablePrintRoute sets whether disable debugPrintRoute
+// If we don't set it, it will default to false
+func WithDisablePrintRoute(b bool) config.Option {
+	return config.Option{F: func(o *config.Options) {
+		o.DisablePrintRoute = b
+	}}
+}
diff --git a/pkg/common/config/option.go b/pkg/common/config/option.go
index 1fc2789..cd69716 100644
--- a/pkg/common/config/option.go
+++ b/pkg/common/config/option.go
@@ -56,6 +56,7 @@ type Options struct {
 	DisablePreParseMultipartForm bool
 	StreamRequestBody            bool
 	NoDefaultServerHeader        bool
+	DisablePrintRoute            bool
 	Network                      string
 	Addr                         string
 	ExitWaitTimeout              time.Duration
@@ -151,6 +152,10 @@ func NewOptions(opts []Option) *Options {
 		// like they are normal requests
 		DisablePreParseMultipartForm: false,
 
+		// Routes info printing is not disabled by default
+		// Disabled when set to True
+		DisablePrintRoute: false,
+
 		// "tcp", "udp", "unix"(unix domain socket)
 		Network: defaultNetwork,
 
diff --git a/pkg/route/engine.go b/pkg/route/engine.go
index 52849d4..812e7f5 100644
--- a/pkg/route/engine.go
+++ b/pkg/route/engine.go
@@ -580,7 +580,10 @@ func (engine *Engine) addRoute(method, path string, handlers app.HandlersChain)
 	utils.Assert(method != "", "HTTP method can not be empty")
 	utils.Assert(len(handlers) > 0, "there must be at least one handler")
 
-	debugPrintRoute(method, path, handlers)
+	if !engine.options.DisablePrintRoute {
+		debugPrintRoute(method, path, handlers)
+	}
+
 	methodRouter := engine.trees.get(method)
 	if methodRouter == nil {
 		methodRouter = &router{method: method, root: &node{}, hasTsrHandler: make(map[string]bool)}


Test patch:
diff --git a/pkg/app/server/option_test.go b/pkg/app/server/option_test.go
index f45eb22..861166c 100644
--- a/pkg/app/server/option_test.go
+++ b/pkg/app/server/option_test.go
@@ -47,6 +47,7 @@ func TestOptions(t *testing.T) {
 		WithStreamBody(false),
 		WithHostPorts(":8888"),
 		WithMaxRequestBodySize(2),
+		WithDisablePrintRoute(true),
 		WithNetwork("unix"),
 		WithExitWaitTime(time.Second),
 		WithMaxKeepBodySize(500),
@@ -71,6 +72,7 @@ func TestOptions(t *testing.T) {
 	assert.DeepEqual(t, opt.StreamRequestBody, false)
 	assert.DeepEqual(t, opt.Addr, ":8888")
 	assert.DeepEqual(t, opt.MaxRequestBodySize, 2)
+	assert.DeepEqual(t, opt.DisablePrintRoute, true)
 	assert.DeepEqual(t, opt.Network, "unix")
 	assert.DeepEqual(t, opt.ExitWaitTimeout, time.Second)
 	assert.DeepEqual(t, opt.MaxKeepBodySize, 500)
@@ -99,6 +101,7 @@ func TestDefaultOptions(t *testing.T) {
 	assert.DeepEqual(t, opt.StreamRequestBody, false)
 	assert.DeepEqual(t, opt.Addr, ":8888")
 	assert.DeepEqual(t, opt.MaxRequestBodySize, 4*1024*1024)
+	assert.DeepEqual(t, opt.DisablePrintRoute, false)
 	assert.DeepEqual(t, opt.Network, "tcp")
 	assert.DeepEqual(t, opt.ExitWaitTimeout, time.Second*5)
 	assert.DeepEqual(t, opt.MaxKeepBodySize, 4*1024*1024)