Skip to content

Commit

Permalink
chore: set log level in Publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Fellows committed Oct 30, 2019
1 parent a08b1ea commit 94da099
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dsl/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"

"github.com/pact-foundation/pact-go/types"
"github.com/hashicorp/logutils"
)

// PactFile is a simple representation of a Pact file to be able to
Expand All @@ -24,10 +25,17 @@ type PactName struct {
// Publisher is the API to send Pact files to a Pact Broker.
type Publisher struct {
pactClient Client

// Log levels.
LogLevel string

// Used to detect if logging has been configured.
logFilter *logutils.LevelFilter
}

// Publish sends the Pacts to a broker, optionally tagging them
func (p *Publisher) Publish(request types.PublishRequest) error {
p.setupLogging()
log.Println("[DEBUG] pact publisher: publish pact")

if p.pactClient == nil {
Expand All @@ -43,3 +51,19 @@ func (p *Publisher) Publish(request types.PublishRequest) error {

return p.pactClient.PublishPacts(request)
}

// Configure logging
func (p *Publisher) setupLogging() {
if p.logFilter == nil {
if p.LogLevel == "" {
p.LogLevel = "INFO"
}
p.logFilter = &logutils.LevelFilter{
Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"},
MinLevel: logutils.LogLevel(p.LogLevel),
Writer: os.Stderr,
}
log.SetOutput(p.logFilter)
}
log.Println("[DEBUG] pact setup logging")
}

0 comments on commit 94da099

Please sign in to comment.