From 98f160e39cadeb737cd631199b9f5e1e30682e94 Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Mon, 4 Mar 2019 19:06:04 +0000 Subject: [PATCH] httpserver: More organized startup output (#2497) * Move SiteOutput to a seperate function sorted by port. * Rename vars and tidy up * Move loopback note to output loop * Fix Typo * Remove unneeded var * Readability Change * Change to other port string. * Simplify as all sites in Server use the same port * Ensure -quiet supresses fmt.Println calls * Prevent double output of siteinfo to log - improve log message * change name of log in comment * Remove spaces * Remove extra line output * final tidy! * Use caddy.LogDestination to setup log * Ensure Log is still output if quiet. * Correct case of functions and make function param bool * Remove conditional check for LogDestination * Revert output to simple blocks * comment update --- caddyhttp/httpserver/server.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/caddyhttp/httpserver/server.go b/caddyhttp/httpserver/server.go index de53cea08..6ec6eff32 100644 --- a/caddyhttp/httpserver/server.go +++ b/caddyhttp/httpserver/server.go @@ -507,16 +507,34 @@ func (s *Server) Stop() error { // OnStartupComplete lists the sites served by this server // and any relevant information, assuming caddy.Quiet == false. func (s *Server) OnStartupComplete() { - if caddy.Quiet { - return + if !caddy.Quiet { + firstSite := s.sites[0] + scheme := "HTTP" + if firstSite.TLS.Enabled { + scheme = "HTTPS" + } + + fmt.Println("") + fmt.Printf("Serving %s on port "+firstSite.Port()+" \n", scheme) + s.outputSiteInfo(false) + fmt.Println("") } + + // Print out process log without header comment + s.outputSiteInfo(true) +} + +func (s *Server) outputSiteInfo(isProcessLog bool) { for _, site := range s.sites { output := site.Addr.String() if caddy.IsLoopback(s.Address()) && !caddy.IsLoopback(site.Addr.Host) { output += " (only accessible on this machine)" } - fmt.Println(output) - log.Println(output) + if isProcessLog { + log.Printf("[INFO] Serving %s \n", output) + } else { + fmt.Println(output) + } } }