-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
caddyconfig: add global option for configuring loggers
This change is aimed at enhancing the logging module within the Caddyfile directive to allow users to configure logs other than the HTTP access log stream, which is the current capability of the Caddyfile [1]. The intent here is to leverage the same syntax as the server log directive at a global level, so that similar customizations can be added without needing to resort to a JSON-based configuration. Discussion for this approach happened in the referenced issue. Closes #3958 [1] https://caddyserver.com/docs/caddyfile/directives/log
- Loading branch information
Showing
9 changed files
with
414 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package httpcaddyfile | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" | ||
_ "github.com/caddyserver/caddy/v2/modules/logging" | ||
) | ||
|
||
func TestGlobalLogOptionSyntax(t *testing.T) { | ||
for i, tc := range []struct { | ||
input string | ||
output string | ||
expectError bool | ||
}{ | ||
// NOTE: Additional test cases of successful Caddyfile parsing | ||
// are present in: caddytest/integration/caddyfile_adapt/ | ||
{ | ||
input: `{ | ||
log default | ||
} | ||
`, | ||
output: `{}`, | ||
expectError: false, | ||
}, | ||
{ | ||
input: `{ | ||
log example { | ||
output file foo.log | ||
} | ||
log example { | ||
format json | ||
} | ||
} | ||
`, | ||
expectError: true, | ||
}, | ||
{ | ||
input: `{ | ||
log example /foo { | ||
output file foo.log | ||
} | ||
} | ||
`, | ||
expectError: true, | ||
}, | ||
} { | ||
|
||
adapter := caddyfile.Adapter{ | ||
ServerType: ServerType{}, | ||
} | ||
|
||
out, _, err := adapter.Adapt([]byte(tc.input), nil) | ||
|
||
if err != nil != tc.expectError { | ||
t.Errorf("Test %d error expectation failed Expected: %v, got %v", i, tc.expectError, err) | ||
continue | ||
} | ||
|
||
if string(out) != tc.output { | ||
t.Errorf("Test %d error output mismatch Expected: %s, got %s", i, tc.output, out) | ||
} | ||
} | ||
} |
Oops, something went wrong.