Skip to content

Commit

Permalink
Allow configuring logger after construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Oct 6, 2023
1 parent 718b3c6 commit 7239daa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions termtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Opts struct {

var TimeoutError = errors.New("timeout")

var VerboseLogger = log.New(os.Stderr, "TermTest: ", log.LstdFlags|log.Lshortfile)

type SetOpt func(o *Opts) error

const DefaultCols = 140
Expand Down Expand Up @@ -94,9 +96,13 @@ func SilenceErrorHandler() ErrorHandler {
}
}

func OptVerboseLogging() SetOpt {
func OptVerboseLogger() SetOpt {
return OptLogger(VerboseLogger)
}

func OptLogger(logger *log.Logger) SetOpt {
return func(o *Opts) error {
o.Logger = log.New(os.Stderr, "TermTest: ", log.LstdFlags|log.Lshortfile)
o.Logger = logger
return nil
}
}
Expand Down Expand Up @@ -183,6 +189,10 @@ func (tt *TermTest) SetErrorHandler(handler ErrorHandler) {
tt.opts.ExpectErrorHandler = handler
}

func (tt *TermTest) SetLogger(logger *log.Logger) {
tt.opts.Logger = logger
}

func (tt *TermTest) SetTest(t *testing.T) {
setTest(tt.opts, t)
}
Expand Down

0 comments on commit 7239daa

Please sign in to comment.