diff --git a/caddy/config.go b/caddy/config.go index 6a311ee8..4f33afb5 100644 --- a/caddy/config.go +++ b/caddy/config.go @@ -226,7 +226,7 @@ func arrangeBindings(allConfigs []server.Config) (Group, error) { return groupings, fatalErr } if warnErr != nil { - log.Println("[Warning]", warnErr) + log.Printf("[WARNING] Resolving bind address for %s: %v", conf.Address(), warnErr) } // Make sure to compare the string representation of the address, diff --git a/caddy/letsencrypt/maintain.go b/caddy/letsencrypt/maintain.go index 62c71428..8f141657 100644 --- a/caddy/letsencrypt/maintain.go +++ b/caddy/letsencrypt/maintain.go @@ -36,24 +36,24 @@ func maintainAssets(configs []server.Config, stopChan chan struct{}) { n, errs := renewCertificates(configs, true) if len(errs) > 0 { for _, err := range errs { - log.Printf("[ERROR] cert renewal: %v\n", err) + log.Printf("[ERROR] Certificate renewal: %v", err) } } // even if there was an error, some renewals may have succeeded if n > 0 && OnChange != nil { err := OnChange() if err != nil { - log.Printf("[ERROR] onchange after cert renewal: %v\n", err) + log.Printf("[ERROR] OnChange after cert renewal: %v", err) } } case <-ocspTicker.C: for bundle, oldStatus := range ocspStatus { _, newStatus, err := acme.GetOCSPForCert(*bundle) if err == nil && newStatus != oldStatus && OnChange != nil { - log.Printf("[INFO] ocsp status changed from %v to %v\n", oldStatus, newStatus) + log.Printf("[INFO] OCSP status changed from %v to %v", oldStatus, newStatus) err := OnChange() if err != nil { - log.Printf("[ERROR] onchange after ocsp update: %v\n", err) + log.Printf("[ERROR] OnChange after OCSP update: %v", err) } break } @@ -75,7 +75,7 @@ func maintainAssets(configs []server.Config, stopChan chan struct{}) { // whatever is listening at 443 better proxy ACME requests to it. // Otherwise, the acme package will create its own listener on 443. func renewCertificates(configs []server.Config, useCustomPort bool) (int, []error) { - log.Print("[INFO] Processing certificate renewals...") + log.Printf("[INFO] Checking certificates for %d hosts", len(configs)) var errs []error var n int @@ -110,7 +110,7 @@ func renewCertificates(configs []server.Config, useCustomPort bool) (int, []erro // Renew with two weeks or less remaining. if daysLeft <= 14 { - log.Printf("[INFO] There are %d days left on the certificate of %s. Trying to renew now.", daysLeft, cfg.Host) + log.Printf("[INFO] Certificate for %s has %d days remaining; attempting renewal", cfg.Host, daysLeft) var client *acme.Client if useCustomPort { client, err = newClientPort("", alternatePort) // email not used for renewal @@ -170,7 +170,7 @@ func renewCertificates(configs []server.Config, useCustomPort bool) (int, []erro n++ } else if daysLeft <= 30 { // Warn on 30 days remaining. TODO: Just do this once... - log.Printf("[WARN] There are %d days left on the certificate for %s. Will renew when 14 days remain.\n", daysLeft, cfg.Host) + log.Printf("[WARNING] Certificate for %s has %d days remaining; will automatically renew when 14 days remain\n", cfg.Host, daysLeft) } } diff --git a/caddy/restart.go b/caddy/restart.go index 30f80ba6..4b52cdac 100644 --- a/caddy/restart.go +++ b/caddy/restart.go @@ -93,7 +93,7 @@ func Restart(newCaddyfile Input) error { sigwpipe.Close() // close our copy of the write end of the pipe or we might be stuck answer, err := ioutil.ReadAll(sigrpipe) if err != nil || len(answer) == 0 { - log.Println("restart: child failed to initialize; changes not applied") + log.Println("[ERROR] Restart: child failed to initialize; changes not applied") return errIncompleteRestart } diff --git a/caddy/setup/root.go b/caddy/setup/root.go index c24b39fb..5100f696 100644 --- a/caddy/setup/root.go +++ b/caddy/setup/root.go @@ -22,7 +22,7 @@ func Root(c *Controller) (middleware.Middleware, error) { if os.IsNotExist(err) { // Allow this, because the folder might appear later. // But make sure the user knows! - log.Printf("Warning: Root path does not exist: %s", c.Root) + log.Printf("[WARNING] Root path does not exist: %s", c.Root) } else { return nil, c.Errf("Unable to access root path '%s': %v", c.Root, err) } diff --git a/caddy/setup/tls.go b/caddy/setup/tls.go index 649c2ecc..4e5f7f9d 100644 --- a/caddy/setup/tls.go +++ b/caddy/setup/tls.go @@ -13,7 +13,7 @@ import ( func TLS(c *Controller) (middleware.Middleware, error) { if c.Port == "http" { c.TLS.Enabled = false - log.Printf("Warning: TLS disabled for %s://%s. To force TLS over the plaintext HTTP port, "+ + log.Printf("[WARNING] TLS disabled for %s://%s. To force TLS over the plaintext HTTP port, "+ "specify port 80 explicitly (https://%s:80).", c.Port, c.Host, c.Host) } else { c.TLS.Enabled = true // they had a tls directive, so assume it's on unless we confirm otherwise later diff --git a/caddy/sigtrap.go b/caddy/sigtrap.go index b9cbec6a..78d2eecc 100644 --- a/caddy/sigtrap.go +++ b/caddy/sigtrap.go @@ -23,7 +23,7 @@ func init() { if len(errs) > 0 { for _, err := range errs { - log.Println(err) + log.Printf("[ERROR] Shutting down: %v", err) } exitCode = 1 } diff --git a/caddy/sigtrap_posix.go b/caddy/sigtrap_posix.go index 0a353b67..8f7aaade 100644 --- a/caddy/sigtrap_posix.go +++ b/caddy/sigtrap_posix.go @@ -42,7 +42,7 @@ func init() { err := Restart(updatedCaddyfile) if err != nil { - log.Println("error at restart:", err) + log.Printf("[ERROR] SIGUSR1: Restart returned: %v", err) } } }() diff --git a/dist/CHANGES.txt b/dist/CHANGES.txt index 623c5cba..fee86d76 100644 --- a/dist/CHANGES.txt +++ b/dist/CHANGES.txt @@ -9,6 +9,7 @@ CHANGES - New -email flag to customize default email used for ACME transactions - New -ca flag to customize ACME CA server URL - New -revoke flag to revoke a certificate +- New -log flag to enable process log - browse: Render filenames with multiple whitespace properly - markdown: Include Last-Modified header in response - startup, shutdown: Better Windows support diff --git a/main.go b/main.go index e2e6b552..818fef71 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,7 @@ func main() { case "": log.SetOutput(ioutil.Discard) default: - file, err := os.Create(logfile) + file, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Fatalf("Error opening log file: %v", err) } @@ -98,7 +98,7 @@ func main() { err = caddy.Start(caddyfile) if err != nil { if caddy.IsRestart() { - log.Println("error starting servers:", err) + log.Printf("[ERROR] Upon starting %s: %v", appName, err) } else { mustLogFatal(err) } diff --git a/middleware/markdown/markdown.go b/middleware/markdown/markdown.go index 3b3bc96e..9f14ca8d 100644 --- a/middleware/markdown/markdown.go +++ b/middleware/markdown/markdown.go @@ -122,7 +122,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error // if development is set, scan directory for file changes for links. if cfg.Development { if err := GenerateStatic(md, cfg); err != nil { - log.Println("On-demand generation error (markdown):", err) + log.Printf("[ERROR] markdown: on-demand site generation error: %v", err) } } diff --git a/middleware/markdown/page.go b/middleware/markdown/page.go index 3185d8ec..2b417d6e 100644 --- a/middleware/markdown/page.go +++ b/middleware/markdown/page.go @@ -92,7 +92,7 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) bool { l.Unlock() return false } else if err != nil { - log.Println("Hash error (markdown):", err) + log.Printf("[ERROR] markdown: Hash error: %v", err) } cfg.Links = []PageLink{} diff --git a/middleware/markdown/process.go b/middleware/markdown/process.go index dc4083b7..0a732477 100644 --- a/middleware/markdown/process.go +++ b/middleware/markdown/process.go @@ -115,10 +115,9 @@ func (md Markdown) processTemplate(c *Config, requestPath string, tmpl []byte, m // generate static page if err = md.generatePage(c, requestPath, b.Bytes()); err != nil { - // if static page generation fails, - // nothing fatal, only log the error. - // TODO: Report this non-fatal error, but don't log it here - log.Println("Rendering error (markdown):", err) + // if static page generation fails, nothing fatal, only log the error. + // TODO: Report (return) this non-fatal error, but don't log it here? + log.Println("[ERROR] markdown: Render:", err) } return b.Bytes(), nil diff --git a/middleware/markdown/watcher.go b/middleware/markdown/watcher.go index 0b39c741..fa5fb3ee 100644 --- a/middleware/markdown/watcher.go +++ b/middleware/markdown/watcher.go @@ -14,7 +14,7 @@ const DefaultInterval = time.Second * 60 func Watch(md Markdown, c *Config, interval time.Duration) (stopChan chan struct{}) { return TickerFunc(interval, func() { if err := GenerateStatic(md, c); err != nil { - log.Println(err) + log.Printf("[ERROR] markdown: Re-generating static site: %v", err) } }) } diff --git a/server/server.go b/server/server.go index d3a42076..5c97914d 100644 --- a/server/server.go +++ b/server/server.go @@ -266,8 +266,7 @@ func (s *Server) Stop() error { err := s.listener.Close() s.listenerMu.Unlock() if err != nil { - // TODO: Better logging - log.Println(err) + log.Printf("[ERROR] Closing listener for %s: %v", s.Addr, err) } return err