From fdc62d015fd5c20e03143e2eea17528892270169 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 18 Aug 2016 07:35:55 -0600 Subject: [PATCH] log: Create log file directory before creating log file --- caddyhttp/log/setup.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/caddyhttp/log/setup.go b/caddyhttp/log/setup.go index 8cdad9f8..87980269 100644 --- a/caddyhttp/log/setup.go +++ b/caddyhttp/log/setup.go @@ -4,6 +4,7 @@ import ( "io" "log" "os" + "path/filepath" "github.com/hashicorp/go-syslog" "github.com/mholt/caddy" @@ -33,8 +34,11 @@ func setup(c *caddy.Controller) error { return err } } else { - var file *os.File - file, err = os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) + err := os.MkdirAll(filepath.Dir(rules[i].OutputFile), 0744) + if err != nil { + return err + } + file, err := os.OpenFile(rules[i].OutputFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) if err != nil { return err }