code: func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
  	state := request.Request{W: w, Req: r}
  	for _, rule := range l.Rules {
  		if !plugin.Name(rule.NameScope).Matches(state.Name()) {
  			continue
  		}
  
  		rrw := dnstest.NewRecorder(w)
  		rc, err := plugin.NextOrFailure(l.Name(), l.Next, ctx, rrw, r)
  
  		if rc > 0 {
  			// There was an error up the chain, but no response has been written yet.
  			// The error must be handled here so the log entry will record the response size.
  			if l.ErrorFunc != nil {
  				l.ErrorFunc(rrw, r, rc)
  			} else {
  				answer := new(dns.Msg)
  				answer.SetRcode(r, rc)
  				state.SizeAndDo(answer)
  
  				vars.Report(state, vars.Dropped, rcode.ToString(rc), answer.Len(), time.Now())
  
  				w.WriteMsg(answer)
  			}
  			rc = 0
  		}
  
  		tpe, _ := response.Typify(rrw.Msg, time.Now().UTC())
  		class := response.Classify(tpe)
  		if rule.Class == response.All || rule.Class == class {
  			rep := replacer.New(r, rrw, CommonLogEmptyValue)
  			rule.Log.Println(rep.Replace(rule.Format))
  		}
  
  		return rc, err
  
  	}
  	return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r)
  }
docs: // ServeDNS implements the plugin.Handler interface.