Commit bcea5182 authored by Matthew Holt's avatar Matthew Holt

Don't truncate process log; more consistent output

parent 2fb4810c
......@@ -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,
......
......@@ -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)
}
}
......
......@@ -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
}
......
......@@ -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)
}
......
......@@ -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
......
......@@ -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
}
......
......@@ -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)
}
}
}()
......
......@@ -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
......
......@@ -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)
}
......
......@@ -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)
}
}
......
......@@ -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{}
......
......@@ -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
......
......@@ -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)
}
})
}
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment