jpillora / ipfilter

A package for IP Filtering in Go (golang)
MIT License
387 stars 47 forks source link

Logger can be overridden from external sources #2

Closed Ruxton closed 7 years ago

Ruxton commented 7 years ago

Allows logger to be overriden with an external logger.

  flags :=  log.Ldate | log.Ltime | log.LUTC
  logger := log.New(os.Stdout, "[stuff] ", flags)

  ipFilter,err := ipfilter.New(ipfilter.Options{
    AllowedIPs: configuration.IPWhiteList,
    BlockByDefault: true,
    Logger: logger,
  })
jpillora commented 7 years ago

Thanks for the PR, though minor change:

    Logger interface {
        Fatal(v ...interface{})
        Fatalf(format string, v ...interface{})
        Fatalln(v ...interface{})
        Flags() int
        Output(calldepth int, s string) error
        Panic(v ...interface{})
        Panicf(format string, v ...interface{})
        Panicln(v ...interface{})
        Prefix() string
        Print(v ...interface{})
        Printf(format string, v ...interface{})
        Println(v ...interface{})
        SetFlags(flag int)
        SetOutput(w io.Writer)
        SetPrefix(prefix string)
    }

should be

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

since this package only makes use of Printf

Ruxton commented 7 years ago

@jpillora have fixed it up

jpillora commented 7 years ago

Merged. Thanks!