mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-22 16:46:53 +01:00
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
This commit is contained in:
parent
4f8020a94c
commit
98f160e39c
1 changed files with 22 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue