mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
middleware/log: allows logging based on response classes (#325)
Add the ability to add a class of responses to be logged; success, denial or error. The default is to log everything (all). Fixes #258
This commit is contained in:
2
middleware/cache/README.md
vendored
2
middleware/cache/README.md
vendored
@@ -20,7 +20,7 @@ Or if you want more control:
|
||||
|
||||
~~~ txt
|
||||
cache [ttl] [zones...] {
|
||||
noerror capacity [ttl]
|
||||
success capacity [ttl]
|
||||
denial capacity [ttl]
|
||||
}
|
||||
~~~
|
||||
|
||||
4
middleware/cache/cache.go
vendored
4
middleware/cache/cache.go
vendored
@@ -60,7 +60,7 @@ type ResponseWriter struct {
|
||||
// WriteMsg implements the dns.ResponseWriter interface.
|
||||
func (c *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
do := false
|
||||
mt, opt := response.Classify(res)
|
||||
mt, opt := response.Typify(res)
|
||||
if opt != nil {
|
||||
do = opt.Do()
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (c *ResponseWriter) set(m *dns.Msg, key string, mt response.Type, duration
|
||||
}
|
||||
|
||||
switch mt {
|
||||
case response.Success, response.Delegation:
|
||||
case response.NoError, response.Delegation:
|
||||
i := newItem(m, duration)
|
||||
c.pcache.Add(key, i)
|
||||
|
||||
|
||||
2
middleware/cache/cache_test.go
vendored
2
middleware/cache/cache_test.go
vendored
@@ -94,7 +94,7 @@ func TestCache(t *testing.T) {
|
||||
m = cacheMsg(m, tc)
|
||||
do := tc.in.Do
|
||||
|
||||
mt, _ := response.Classify(m)
|
||||
mt, _ := response.Typify(m)
|
||||
k := key(m, mt, do)
|
||||
crr.set(m, k, mt, c.pttl)
|
||||
|
||||
|
||||
4
middleware/cache/item.go
vendored
4
middleware/cache/item.go
vendored
@@ -87,7 +87,7 @@ func setMsgTTL(m *dns.Msg, ttl uint32) {
|
||||
}
|
||||
|
||||
func minMsgTTL(m *dns.Msg, mt response.Type) time.Duration {
|
||||
if mt != response.Success && mt != response.NameError && mt != response.NoData {
|
||||
if mt != response.NoError && mt != response.NameError && mt != response.NoData {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func minMsgTTL(m *dns.Msg, mt response.Type) time.Duration {
|
||||
if r.Header().Rrtype == dns.TypeSOA {
|
||||
return time.Duration(r.(*dns.SOA).Minttl) * time.Second
|
||||
}
|
||||
case response.Success, response.Delegation:
|
||||
case response.NoError, response.Delegation:
|
||||
if r.Header().Ttl < uint32(minTTL.Seconds()) {
|
||||
minTTL = time.Duration(r.Header().Ttl) * time.Second
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user