Skip to content

Commit

Permalink
chore: fix missing log package
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 7, 2021
1 parent 3c52a0a commit 05ac8e3
Show file tree
Hide file tree
Showing 4 changed files with 1,516 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ _*
pact-go
pacts
logs
log
tmp
coverage.txt

Expand Down
53 changes: 53 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package log

import (
"fmt"
"log"
"os"

"github.com/hashicorp/logutils"
)

var logFilter *logutils.LevelFilter
var defaultLogLevel = "INFO"

const (
logLevelTrace logutils.LogLevel = "TRACE"
logLevelDebug = "DEBUG"
logLevelInfo = "INFO"
logLevelWarn = "WARN"
logLevelError = "ERROR"
)

func InitLogging() {
if logFilter == nil {
logFilter = &logutils.LevelFilter{
Levels: []logutils.LogLevel{logLevelTrace, logLevelDebug, logLevelInfo, logLevelWarn, logLevelError},
MinLevel: logutils.LogLevel(defaultLogLevel),
Writer: os.Stderr,
}
log.SetOutput(logFilter)
}
log.Println("[DEBUG] initialised logging")

}

// SetLogLevel sets the default log level for the Pact framework
func SetLogLevel(level logutils.LogLevel) error {
switch level {
case logLevelTrace, logLevelDebug, logLevelError, logLevelInfo, logLevelWarn:
logFilter.SetMinLevel(level)
return nil
default:
return fmt.Errorf(`invalid logLevel '%s'. Please specify one of "TRACE", "DEBUG", "INFO", "WARN", "ERROR"`, level)
}
}

// LogLevel gets the current log level for the Pact framework
func LogLevel() logutils.LogLevel {
if logFilter != nil {
return logFilter.MinLevel
}

return logutils.LogLevel(defaultLogLevel)
}
Loading

0 comments on commit 05ac8e3

Please sign in to comment.