Allow to skip specifying logger so default log package will be used.
This commit is contained in:
parent
79495d352c
commit
1330c5f1b6
16
exported.go
16
exported.go
@ -23,12 +23,26 @@
|
||||
|
||||
package flagger
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
logger LoggerInterface
|
||||
)
|
||||
|
||||
// New creates new Flagger instance.
|
||||
// If no logger will be passed - we will use default "log" module and will
|
||||
// print logs to stdout.
|
||||
func New(l LoggerInterface) *Flagger {
|
||||
logger = l
|
||||
if l == nil {
|
||||
lg := log.New(os.Stdout, "Flagger: ", log.LstdFlags)
|
||||
logger = LoggerInterface(lg)
|
||||
} else {
|
||||
logger = l
|
||||
}
|
||||
f := Flagger{}
|
||||
return &f
|
||||
}
|
||||
|
@ -43,6 +43,15 @@ func TestFlaggerInitialization(t *testing.T) {
|
||||
f.Initialize()
|
||||
}
|
||||
|
||||
func TestFlaggerInitializationWithNilLogger(t *testing.T) {
|
||||
fl := New(nil)
|
||||
if f == nil {
|
||||
t.Fatal("Logger initialization failed!")
|
||||
t.FailNow()
|
||||
}
|
||||
fl.Initialize()
|
||||
}
|
||||
|
||||
func TestFlaggerAddBoolFlag(t *testing.T) {
|
||||
flagTestBool := Flag{
|
||||
Name: "testboolflag",
|
||||
|
Loading…
Reference in New Issue
Block a user