Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract logger. #563

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ type Updater interface {
OverrideConfig(*Config) error
}

type Logger interface {
Printf(format string, v ...interface{})
Print(v ...interface{})
Println(v ...interface{})
}

// Config passes along Amass configuration settings and options.
type Config struct {
sync.Mutex
Expand All @@ -57,7 +63,7 @@ type Config struct {
UUID uuid.UUID

// Logger for error messages
Log *log.Logger
Log Logger

// The directory that stores the bolt db and other files created
Dir string `ini:"output_directory"`
Expand Down
4 changes: 2 additions & 2 deletions resolvers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ type baseResolver struct {
readMsgs queue.Queue
wildcardChannels *wildcardChans
address string
log *log.Logger
log Logger
perSec int
conn *dns.Conn
}

// NewBaseResolver initializes a Resolver that send DNS queries to the provided IP address.
func NewBaseResolver(addr string, perSec int, logger *log.Logger) Resolver {
func NewBaseResolver(addr string, perSec int, logger Logger) Resolver {
if _, _, err := net.SplitHostPort(addr); err != nil {
// Add the default port number to the IP address
addr = net.JoinHostPort(addr, "53")
Expand Down
7 changes: 7 additions & 0 deletions resolvers/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package resolvers

type Logger interface {
Printf(format string, v ...interface{})
Print(v ...interface{})
Println(v ...interface{})
}
4 changes: 2 additions & 2 deletions resolvers/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type resolverPool struct {
sync.Mutex
done chan struct{}
// Logger for error messages
log *log.Logger
log Logger
baseline Resolver
resolvers []Resolver
curIdx int
Expand All @@ -28,7 +28,7 @@ type resolverPool struct {
}

// NewResolverPool initializes a ResolverPool that uses the provided Resolvers.
func NewResolverPool(resolvers []Resolver, delay time.Duration, baseline Resolver, logger *log.Logger) Resolver {
func NewResolverPool(resolvers []Resolver, delay time.Duration, baseline Resolver, logger Logger) Resolver {
if len(resolvers) == 0 {
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions systems/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"log"
"os"
"runtime"
"sort"
Expand All @@ -23,6 +22,12 @@ import (
"github.com/miekg/dns"
)

type Logger interface {
Printf(format string, v ...interface{})
Print(v ...interface{})
Println(v ...interface{})
}

// LocalSystem implements a System to be executed within a single process.
type LocalSystem struct {
cfg *config.Config
Expand Down Expand Up @@ -324,7 +329,7 @@ func publicResolverSetup(cfg *config.Config, max int) resolvers.Resolver {
return resolvers.NewResolverPool(r, 5*time.Second, baseline, cfg.Log)
}

func setupResolvers(addrs []string, max, rate int, log *log.Logger) []resolvers.Resolver {
func setupResolvers(addrs []string, max, rate int, log Logger) []resolvers.Resolver {
if len(addrs) <= 0 {
return nil
}
Expand Down