From 9b74901b40d0b1f2bafceceaf98174252d8208d4 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 28 Apr 2015 13:05:01 -0600 Subject: [PATCH] errors: Fix file paths for error pages & empty log filenames --- middleware/errors/errors.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/middleware/errors/errors.go b/middleware/errors/errors.go index d89a95fde..36c7c5d72 100644 --- a/middleware/errors/errors.go +++ b/middleware/errors/errors.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "path" "strconv" "github.com/mholt/caddy/middleware" @@ -28,7 +29,7 @@ func New(c middleware.Controller) (middleware.Middleware, error) { file = os.Stdout } else if handler.LogFile == "stderr" { file = os.Stderr - } else { + } else if handler.LogFile != "" { file, err = os.OpenFile(handler.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) if err != nil { return err @@ -131,6 +132,7 @@ func parse(c middleware.Controller) (ErrorHandler, error) { handler.LogFile = where } else { // Error page; ensure it exists + where = path.Join(c.Root(), where) f, err := os.Open(where) if err != nil { return hadBlock, c.Err("Unable to open error page '" + where + "': " + err.Error())