mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-19 05:59:03 -04:00
Modify Startup Output (#2469)
* Move SiteOutput to a seperate function. * 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 * Use caddy.LogDestination to setup log * Ensure Log is still output if quiet.
This commit is contained in:
@@ -507,16 +507,35 @@ 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("fmt")
|
||||
}
|
||||
// if caddy process log is going to stdout, printing to log
|
||||
// here would duplicate to stdout so dont. If -quiet ensure
|
||||
// that Log is still output even if process log startup isnt. #2469
|
||||
if caddy.LogDestination != "stdout" || caddy.Quiet {
|
||||
s.OutputSiteInfo("log")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) OutputSiteInfo(LogType string) {
|
||||
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 LogType == "fmt" {
|
||||
fmt.Println(output)
|
||||
} else {
|
||||
log.Printf("[INFO] Serving %s \n", output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user