mirror of
https://github.com/coredns/coredns.git
synced 2025-11-08 13:06:24 -05:00
[plugin/log] Expand {combined} and {common} in log format (#5230)
This PR tries to address the issue raised in 5223 where `{combined}`
or `{common}` in log format will not expand when `{combined}` or `{common}`
is not the only token in the format.
This PR fixes 5223.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -129,6 +129,26 @@ func TestLogParse(t *testing.T) {
|
||||
{`log {
|
||||
unknown
|
||||
}`, true, []Rule{}},
|
||||
{`log example.org "{combined} {/forward/upstream}"`, false, []Rule{{
|
||||
NameScope: "example.org.",
|
||||
Format: CombinedLogFormat + " {/forward/upstream}",
|
||||
Class: map[response.Class]struct{}{response.All: {}},
|
||||
}}},
|
||||
{`log example.org "{common} {/forward/upstream}"`, false, []Rule{{
|
||||
NameScope: "example.org.",
|
||||
Format: CommonLogFormat + " {/forward/upstream}",
|
||||
Class: map[response.Class]struct{}{response.All: {}},
|
||||
}}},
|
||||
{`log example.org "{when} {combined} {/forward/upstream}"`, false, []Rule{{
|
||||
NameScope: "example.org.",
|
||||
Format: "{when} " + CombinedLogFormat + " {/forward/upstream}",
|
||||
Class: map[response.Class]struct{}{response.All: {}},
|
||||
}}},
|
||||
{`log example.org "{when} {common} {/forward/upstream}"`, false, []Rule{{
|
||||
NameScope: "example.org.",
|
||||
Format: "{when} " + CommonLogFormat + " {/forward/upstream}",
|
||||
Class: map[response.Class]struct{}{response.All: {}},
|
||||
}}},
|
||||
}
|
||||
for i, test := range tests {
|
||||
c := caddy.NewTestController("dns", test.inputLogRules)
|
||||
@@ -141,7 +161,7 @@ func TestLogParse(t *testing.T) {
|
||||
i, test.inputLogRules, err)
|
||||
}
|
||||
if len(actualLogRules) != len(test.expectedLogRules) {
|
||||
t.Fatalf("Test %d expected %d no of Log rules, but got %d ",
|
||||
t.Fatalf("Test %d expected %d no of Log rules, but got %d",
|
||||
i, len(test.expectedLogRules), len(actualLogRules))
|
||||
}
|
||||
for j, actualLogRule := range actualLogRules {
|
||||
|
||||
Reference in New Issue
Block a user