changed to logrus

This commit is contained in:
Andrey Meshkov 2018-12-24 15:27:14 +03:00
parent e711f6e5fe
commit 0a977fee87
6 changed files with 34 additions and 19 deletions

View File

@ -7,6 +7,8 @@ import (
"sync"
"time"
"github.com/pkg/errors"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/dnsproxy/proxy"
@ -97,21 +99,19 @@ func (s *Server) startInternal(config *ServerConfig) error {
s.ServerConfig = *config
}
if s.dnsFilter == nil {
log.Printf("Creating dnsfilter")
s.dnsFilter = dnsfilter.New(&s.Config)
// add rules only if they are enabled
if s.FilteringEnabled {
// TODO: Handle error
s.dnsFilter.AddRules(s.Filters)
if s.dnsFilter != nil || s.dnsProxy != nil {
return errors.New("DNS server is already started")
}
err := s.initDNSFilter()
if err != nil {
return err
}
log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog()
err = fillStatsFromQueryLog()
if err != nil {
log.Printf("Failed to load stats from querylog: %s", err)
return err
return errorx.Decorate(err, "failed to load stats from querylog")
}
once.Do(func() {
@ -139,12 +139,23 @@ func (s *Server) startInternal(config *ServerConfig) error {
proxyConfig.Upstreams = defaultValues.Upstreams
}
// TODO: Don't let call Start the second time
// Initialize the DNS proxy
// Initialize and start the DNS proxy
s.dnsProxy = &proxy.Proxy{Config: proxyConfig}
return s.dnsProxy.Start()
}
err = s.dnsProxy.Start()
return err
// Initializes the DNS filter
func (s *Server) initDNSFilter() error {
log.Printf("Creating dnsfilter")
s.dnsFilter = dnsfilter.New(&s.Config)
// add rules only if they are enabled
if s.FilteringEnabled {
err := s.dnsFilter.AddRules(s.Filters)
if err != nil {
return errorx.Decorate(err, "could not initialize dnsfilter")
}
}
return nil
}
// Stop stops the DNS server

View File

@ -3,7 +3,6 @@ package dnsforward
import (
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
"strings"
@ -12,6 +11,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
"github.com/miekg/dns"
log "github.com/sirupsen/logrus"
)
const (

View File

@ -5,11 +5,12 @@ import (
"compress/gzip"
"encoding/json"
"fmt"
"log"
"os"
"sync"
"time"
log "github.com/sirupsen/logrus"
"github.com/go-test/deep"
)

View File

@ -3,7 +3,6 @@ package dnsforward
import (
"bytes"
"fmt"
"log"
"net/http"
"os"
"path"
@ -14,6 +13,8 @@ import (
"sync"
"time"
log "github.com/sirupsen/logrus"
"github.com/bluele/gcache"
"github.com/miekg/dns"
)

View File

@ -3,11 +3,12 @@ package dnsforward
import (
"encoding/json"
"fmt"
"log"
"net/http"
"sync"
"time"
log "github.com/sirupsen/logrus"
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
)

1
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/joomcode/errorx v0.1.0
github.com/miekg/dns v1.1.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.8.0
github.com/shirou/gopsutil v2.18.10+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/sirupsen/logrus v1.2.0