Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
418edd2a
Commit
418edd2a
authored
Jan 08, 2019
by
ckcd
Committed by
Miek Gieben
Jan 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/log: support multi nameScope (#2420)
parent
53d1afba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
25 deletions
+69
-25
plugin/log/README.md
plugin/log/README.md
+3
-3
plugin/log/setup.go
plugin/log/setup.go
+37
-22
plugin/log/setup_test.go
plugin/log/setup_test.go
+29
-0
No files found.
plugin/log/README.md
View file @
418edd2a
...
@@ -23,10 +23,10 @@ log
...
@@ -23,10 +23,10 @@ log
Or if you want/need slightly more control:
Or if you want/need slightly more control:
~~~
txt
~~~
txt
log [NAME] [FORMAT]
log [NAME
S...
] [FORMAT]
~~~
~~~
*
`NAME
`
is the name
to match in order to be logged
*
`NAME
S`
is the name list
to match in order to be logged
*
`FORMAT`
is the log format to use (default is Common Log Format),
`{common}`
is used as a shortcut
*
`FORMAT`
is the log format to use (default is Common Log Format),
`{common}`
is used as a shortcut
for the Common Log Format. You can also use
`{combined}`
for a format that adds the query opcode
for the Common Log Format. You can also use
`{combined}`
for a format that adds the query opcode
`{>opcode}`
to the Common Log Format.
`{>opcode}`
to the Common Log Format.
...
@@ -34,7 +34,7 @@ log [NAME] [FORMAT]
...
@@ -34,7 +34,7 @@ log [NAME] [FORMAT]
You can further specify the classes of responses that get logged:
You can further specify the classes of responses that get logged:
~~~
txt
~~~
txt
log [NAME] [FORMAT] {
log [NAME
S...
] [FORMAT] {
class CLASSES...
class CLASSES...
}
}
~~~
~~~
...
...
plugin/log/setup.go
View file @
418edd2a
package
log
package
log
import
(
import
(
"strings"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/response"
"github.com/coredns/coredns/plugin/pkg/response"
...
@@ -34,62 +36,75 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
...
@@ -34,62 +36,75 @@ func logParse(c *caddy.Controller) ([]Rule, error) {
for
c
.
Next
()
{
for
c
.
Next
()
{
args
:=
c
.
RemainingArgs
()
args
:=
c
.
RemainingArgs
()
length
:=
len
(
rules
)
if
len
(
args
)
==
0
{
switch
len
(
args
)
{
case
0
:
// Nothing specified; use defaults
// Nothing specified; use defaults
rules
=
append
(
rules
,
Rule
{
rules
=
append
(
rules
,
Rule
{
NameScope
:
"."
,
NameScope
:
"."
,
Format
:
DefaultLogFormat
,
Format
:
DefaultLogFormat
,
Class
:
make
(
map
[
response
.
Class
]
struct
{}),
Class
:
make
(
map
[
response
.
Class
]
struct
{}),
})
})
}
else
if
len
(
args
)
==
1
{
case
1
:
rules
=
append
(
rules
,
Rule
{
rules
=
append
(
rules
,
Rule
{
NameScope
:
dns
.
Fqdn
(
args
[
0
]),
NameScope
:
dns
.
Fqdn
(
args
[
0
]),
Format
:
DefaultLogFormat
,
Format
:
DefaultLogFormat
,
Class
:
make
(
map
[
response
.
Class
]
struct
{}),
Class
:
make
(
map
[
response
.
Class
]
struct
{}),
})
})
}
else
{
default
:
// Name scope, and maybe a format specified
// Name scope
s
, and maybe a format specified
format
:=
DefaultLogFormat
format
:=
DefaultLogFormat
switch
args
[
1
]
{
if
strings
.
Contains
(
args
[
len
(
args
)
-
1
],
"{"
)
{
case
"{common}"
:
switch
args
[
len
(
args
)
-
1
]
{
format
=
CommonLogFormat
case
"{common}"
:
case
"{combined}"
:
format
=
CommonLogFormat
format
=
CombinedLogFormat
case
"{combined}"
:
default
:
format
=
CombinedLogFormat
format
=
args
[
1
]
default
:
format
=
args
[
len
(
args
)
-
1
]
}
args
=
args
[
:
len
(
args
)
-
1
]
}
}
rules
=
append
(
rules
,
Rule
{
for
_
,
str
:=
range
args
{
NameScope
:
dns
.
Fqdn
(
args
[
0
]),
rules
=
append
(
rules
,
Rule
{
Format
:
format
,
NameScope
:
dns
.
Fqdn
(
str
),
Class
:
make
(
map
[
response
.
Class
]
struct
{}),
Format
:
format
,
})
Class
:
make
(
map
[
response
.
Class
]
struct
{}),
})
}
}
}
// Class refinements in an extra block.
// Class refinements in an extra block.
classes
:=
make
(
map
[
response
.
Class
]
struct
{})
for
c
.
NextBlock
()
{
for
c
.
NextBlock
()
{
switch
c
.
Val
()
{
switch
c
.
Val
()
{
// class followed by combinations of all, denial, error and success.
// class followed by combinations of all, denial, error and success.
case
"class"
:
case
"class"
:
classes
:=
c
.
RemainingArgs
()
classes
Args
:=
c
.
RemainingArgs
()
if
len
(
classes
)
==
0
{
if
len
(
classes
Args
)
==
0
{
return
nil
,
c
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
}
for
_
,
c
:=
range
classes
{
for
_
,
c
:=
range
classes
Args
{
cls
,
err
:=
response
.
ClassFromString
(
c
)
cls
,
err
:=
response
.
ClassFromString
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
rules
[
len
(
rules
)
-
1
]
.
Clas
s
[
cls
]
=
struct
{}{}
classe
s
[
cls
]
=
struct
{}{}
}
}
default
:
default
:
return
nil
,
c
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
}
}
}
if
len
(
rules
[
len
(
rules
)
-
1
]
.
Class
)
==
0
{
if
len
(
classes
)
==
0
{
rules
[
len
(
rules
)
-
1
]
.
Class
[
response
.
All
]
=
struct
{}{}
classes
[
response
.
All
]
=
struct
{}{}
}
for
i
:=
len
(
rules
)
-
1
;
i
>=
length
;
i
-=
1
{
rules
[
i
]
.
Class
=
classes
}
}
}
}
...
...
plugin/log/setup_test.go
View file @
418edd2a
...
@@ -55,6 +55,35 @@ func TestLogParse(t *testing.T) {
...
@@ -55,6 +55,35 @@ func TestLogParse(t *testing.T) {
Format
:
"{when}"
,
Format
:
"{when}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}{}},
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}{}},
}}},
}}},
{
`log example.org example.net`
,
false
,
[]
Rule
{{
NameScope
:
"example.org."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}{}},
},
{
NameScope
:
"example.net."
,
Format
:
DefaultLogFormat
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}{}},
}}},
{
`log example.org example.net {host}`
,
false
,
[]
Rule
{{
NameScope
:
"example.org."
,
Format
:
"{host}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}{}},
},
{
NameScope
:
"example.net."
,
Format
:
"{host}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
All
:
struct
{}{}},
}}},
{
`log example.org example.net {when} {
class denial
}`
,
false
,
[]
Rule
{{
NameScope
:
"example.org."
,
Format
:
"{when}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
Denial
:
struct
{}{}},
},
{
NameScope
:
"example.net."
,
Format
:
"{when}"
,
Class
:
map
[
response
.
Class
]
struct
{}{
response
.
Denial
:
struct
{}{}},
}}},
{
`log example.org {
{
`log example.org {
class all
class all
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment