Skip to content

Commit 98f160e

Browse files
tobyamholt
authored andcommitted
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
1 parent 4f8020a commit 98f160e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

caddyhttp/httpserver/server.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,34 @@ func (s *Server) Stop() error {
507507
// OnStartupComplete lists the sites served by this server
508508
// and any relevant information, assuming caddy.Quiet == false.
509509
func (s *Server) OnStartupComplete() {
510-
if caddy.Quiet {
511-
return
510+
if !caddy.Quiet {
511+
firstSite := s.sites[0]
512+
scheme := "HTTP"
513+
if firstSite.TLS.Enabled {
514+
scheme = "HTTPS"
515+
}
516+
517+
fmt.Println("")
518+
fmt.Printf("Serving %s on port "+firstSite.Port()+" \n", scheme)
519+
s.outputSiteInfo(false)
520+
fmt.Println("")
512521
}
522+
523+
// Print out process log without header comment
524+
s.outputSiteInfo(true)
525+
}
526+
527+
func (s *Server) outputSiteInfo(isProcessLog bool) {
513528
for _, site := range s.sites {
514529
output := site.Addr.String()
515530
if caddy.IsLoopback(s.Address()) && !caddy.IsLoopback(site.Addr.Host) {
516531
output += " (only accessible on this machine)"
517532
}
518-
fmt.Println(output)
519-
log.Println(output)
533+
if isProcessLog {
534+
log.Printf("[INFO] Serving %s \n", output)
535+
} else {
536+
fmt.Println(output)
537+
}
520538
}
521539
}
522540

0 commit comments

Comments
 (0)