diff --git a/caddyhttp/log/setup.go b/caddyhttp/log/setup.go index f02faf82b..35a46bbdc 100644 --- a/caddyhttp/log/setup.go +++ b/caddyhttp/log/setup.go @@ -53,42 +53,36 @@ func logParse(c *caddy.Controller) ([]*Rule, error) { } } - if len(args) == 0 { - // Nothing specified; use defaults - rules = appendEntry(rules, "/", &Entry{ - Log: &httpserver.Logger{ - Output: DefaultLogFilename, - Roller: logRoller, - }, - Format: DefaultLogFormat, - }) - } else if len(args) == 1 { + path := "/" + format := DefaultLogFormat + output := DefaultLogFilename + + switch len(args) { + case 0: + // nothing to change + case 1: // Only an output file specified - rules = appendEntry(rules, "/", &Entry{ - Log: &httpserver.Logger{ - Output: args[0], - Roller: logRoller, - }, - Format: DefaultLogFormat, - }) - } else { + output = args[0] + case 2, 3: // Path scope, output file, and maybe a format specified - - format := DefaultLogFormat - + path = args[0] + output = args[1] if len(args) > 2 { format = strings.Replace(args[2], "{common}", CommonLogFormat, -1) format = strings.Replace(format, "{combined}", CombinedLogFormat, -1) } - - rules = appendEntry(rules, args[0], &Entry{ - Log: &httpserver.Logger{ - Output: args[1], - Roller: logRoller, - }, - Format: format, - }) + default: + // Maximum number of args in log directive is 3. + return nil, c.ArgErr() } + + rules = appendEntry(rules, path, &Entry{ + Log: &httpserver.Logger{ + Output: output, + Roller: logRoller, + }, + Format: format, + }) } return rules, nil diff --git a/caddyhttp/log/setup_test.go b/caddyhttp/log/setup_test.go index 35e7c5327..e0b27beb7 100644 --- a/caddyhttp/log/setup_test.go +++ b/caddyhttp/log/setup_test.go @@ -227,6 +227,7 @@ func TestLogParse(t *testing.T) { }}}, {`log access.log { rotate_size }`, true, nil}, {`log access.log { invalid_option 1 }`, true, nil}, + {`log / acccess.log "{remote} - [{when}] "{method} {port}" {scheme} {mitm} "`, true, nil}, } for i, test := range tests { c := caddy.NewTestController("http", test.inputLogRules)