mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -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:
		| @@ -7,6 +7,7 @@ import ( | ||||
|  | ||||
| 	"github.com/miekg/coredns/core/dnsserver" | ||||
| 	"github.com/miekg/coredns/middleware" | ||||
| 	"github.com/miekg/coredns/middleware/pkg/response" | ||||
|  | ||||
| 	"github.com/hashicorp/go-syslog" | ||||
| 	"github.com/mholt/caddy" | ||||
| @@ -105,6 +106,26 @@ func logParse(c *caddy.Controller) ([]Rule, error) { | ||||
| 				Format:     format, | ||||
| 			}) | ||||
| 		} | ||||
|  | ||||
| 		// Class refinements in an extra block. | ||||
| 		for c.NextBlock() { | ||||
| 			switch c.Val() { | ||||
| 			// class followed by all, denial, error or success. | ||||
| 			case "class": | ||||
| 				classes := c.RemainingArgs() | ||||
| 				if len(classes) == 0 { | ||||
| 					return nil, c.ArgErr() | ||||
| 				} | ||||
| 				cls, err := response.ClassFromString(classes[0]) | ||||
| 				if err != nil { | ||||
| 					return nil, err | ||||
| 				} | ||||
| 				// update class and the last added Rule (bit icky) | ||||
| 				rules[len(rules)-1].Class = cls | ||||
| 			default: | ||||
| 				return nil, c.ArgErr() | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return rules, nil | ||||
|   | ||||
		Reference in New Issue
	
	Block a user