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

[FEATURE REQUEST] Disable verbose routes & controllers logging #1630

Closed
AlbinoGeek opened this issue Sep 13, 2020 · 7 comments
Closed

[FEATURE REQUEST] Disable verbose routes & controllers logging #1630

AlbinoGeek opened this issue Sep 13, 2020 · 7 comments

Comments

@AlbinoGeek
Copy link

AlbinoGeek commented Sep 13, 2020

Summary

I added iris.WithoutBanner, iris.WithoutStartupLog and while the two-line banner was removed, the entire startup log showed unmodified than without providing the parameter.

Versions, etc.

Thing Version
Golang 1.14.7 linux/amd64
Iris master fd5a2a7
Kernel 5.8.4-200.fc32.x86_64
OS Fedora 32 Workstation

Code

	app.Run(
		iris.AutoTLS(
			// internal IP:port the TLS server listens on
			fmt.Sprintf("%s:%d", viper.GetString("addr.internal.ip"), viper.GetInt("addr.internal.port-secure")),

			// all domains to ask letsencrypt to provide certificates for
			strings.Join(buildDomainsList(true, ""), " "),

			// email address letsencrypt certbot will notify about expirations
			viper.GetString("email.certmaster"),

			// Required for acme HTTP-01 challenge to succeed
			iris.AutoTLSNoRedirect(func(acme func(http.Handler) http.Handler) *http.Server {
				srv := &http.Server{
					// internal IP:port the plain HTTP server listens on
					Addr: fmt.Sprintf("%s:%d", viper.GetString("addr.internal.ip"), viper.GetInt("addr.internal.port-plain")),

					// callback run when a request isn't an acme challenge
					Handler: acme(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
						// redirect user to our application hosted on TLS
						http.Redirect(w, r, publicURL+r.URL.EscapedPath(), iris.StatusTemporaryRedirect)
					})),
				}
				go srv.ListenAndServe()
				return srv
			}),
		),
		iris.WithRemoteAddrHeader("CF-Connecting-IP", "True-Client-IP"),
		iris.WithoutBanner,     // removes "Now listening on: ...\nApplication started. ..."
		iris.WithoutStartupLog,
	)

Output

[DBUG] 2020/09/13 13:48 API: 27 registered routes (18 GET, 3 HEAD, 1 POST, 2 OPTIONS and 3 ERROR)                                                                                                                                      
GET: / ./public (./main.go:114)                                                                                                                                                                                                        
     • iris.recover (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/recover/recover.go:27)                                                                                  
     • iris-contrib/middleware/cors.(*Cors).Serve-fm (/home/damon/go/pkg/mod/github.com/iris-contrib/middleware/[email protected]/cors.go:169)                                                                   
     • iris/core/router.FileServer.func2 (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/core/router/fs.go:187)
// ...
@kataras
Copy link
Owner

kataras commented Sep 13, 2020

@AlbinoGeek both WithoutBanner and WithoutStartupLog do the same thing (one is kept for backwards compatibility back in v11), they don't show the banner the "Now Listening On...." The Output below is coming from the "debug" logger level.

@kataras kataras removed their assignment Sep 13, 2020
@AlbinoGeek
Copy link
Author

Ahh, okay! Thank you for explaining this. Somehow I missed the comment in the godoc.

@kataras
Copy link
Owner

kataras commented Sep 13, 2020

No worries, do you want to make any modifications there? e.g make the startuplog to disable both banner and the API trace?

@AlbinoGeek
Copy link
Author

Perhaps a way to split up the two different kinds of debug output in the startup log and selectively disable them?

Type 1

[DBUG] public.PublicController                                                                                                                                                                                                         
  ╺ Get
      GET /
    • iris.Context
  ╺ GetHealth
      GET /health
    • iris.Context

Type 2

GET: / public.PublicController (./main.go:191)
     • iris.recover (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/recover/recover.go:27)
     • iris.basicauth (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/basicauth/basicauth.go:110)
     • iris.cache (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/cache/client/handler.go:119)
     • [redacted]/controllers/base.populateViewData (./controllers/base/populateViewData.go:11)
     • public.PublicController.Get (./controllers/public/Public.go:35)
GET: /health public.PublicController (./main.go:191)                                                               
     • iris.recover (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/recover/recover.go:27)
     • iris.basicauth (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/middleware/basicauth/basicauth.go:110)
     • iris.cache (/home/damon/go/pkg/mod/github.com/kataras/iris/[email protected]/cache/client/handler.go:119)
     • [redacted]/controllers/base.populateViewData (./controllers/base/populateViewData.go:11)
     • public.PublicController.GetHealth (./controllers/public/Public.go:27)

@kataras
Copy link
Owner

kataras commented Sep 14, 2020

OK @AlbinoGeek, for the Type 2 you could already disable it per-route. I've just pushed a commit which you can disable per party and its children (must be called before routes register). And on the Type 1, respectfully, you have the mvc/Application.SetControllersNoLog(disable bool) now.

Type 2

Disable all routes verbose logging:

app := iris.New()
app.SetRoutesNoLog(true)

Disable true (or enable false if parent disabled it) all routes verbose logging under the "/users" Party:

u := app.Party("/users").SetRoutesNoLog(true)
u.Get(...)

Type 1

m := mvc.New(app).SetControllersNoLog(true)
m.Handle(...)

I took the initiative to change the title of this issue, if that's OK with you.

@kataras kataras changed the title [BUG] iris.WithoutStartupLog doesn't work [FEATURE REQUEST] Disable verbose routes & controllers logging Sep 14, 2020
@kataras kataras added this to the v12.2.0 milestone Sep 14, 2020
@AlbinoGeek
Copy link
Author

Totally acceptable! Thank you, this is wonderful. Basically, the need came about because golog (and therefore iris) doesn't have a Trace level, so we effectively have to treat Debug as if it were Trace while having other options to toggle extra verbosity around the framework, such as this.

Thank you!

@kataras
Copy link
Owner

kataras commented Sep 15, 2020

Yeah we dont have a Trace level yet, but its not hard to add one. But even if we had trace level this will disable/enable both type 1 and type 2, but you wanted to disable them selectively so... methods like these would exist even if we had trace level...therefore a Trace level is useless for now

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

No branches or pull requests

2 participants