Skip to content

Commit

Permalink
Merge branch 'main' into binding_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sambhav authored Oct 4, 2021
2 parents 0496d9f + 8496ef4 commit d29fc72
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion application.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type BuildTOML struct {
}

func (b BuildTOML) isEmpty() bool {
return len(b.Unmet) == 0
return len(b.BOM) == 0 && len(b.Unmet) == 0
}

// BOMEntry contains a bill of materials entry.
Expand Down
16 changes: 13 additions & 3 deletions poet/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ func NewLoggerWithOptions(writer io.Writer, options ...Option) Logger {
func NewLogger(writer io.Writer) Logger {
var options []Option

if _, ok := os.LookupEnv("BP_DEBUG"); ok {
options = append(options, WithDebug(writer))
}
// check for presence and value of log level environment variable
options = LogLevel(options, writer)

return NewLoggerWithOptions(writer, options...)
}

func LogLevel(options []Option, writer io.Writer) []Option {
// Check for older log level env variable
_, dbSet := os.LookupEnv("BP_DEBUG")

// Then check for common buildpack log level env variable - if either are set to DEBUG/true, enable Debug Writer
if level, ok := os.LookupEnv("BP_LOG_LEVEL"); (ok && strings.ToLower(level) == "debug") || dbSet {
options = append(options, WithDebug(writer))
}
return options
}

// Debug formats using the default formats for its operands and writes to the configured debug writer. Spaces are added
// between operands when neither is a string.
func (l Logger) Debug(a ...interface{}) {
Expand Down
15 changes: 15 additions & 0 deletions poet/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ func testLogger(t *testing.T, context spec.G, it spec.S) {
})
})

context("with BP_LOG_LEVEL set to DEBUG", func() {
it.Before(func() {
Expect(os.Setenv("BP_LOG_LEVEL", "DEBUG")).To(Succeed())
l = poet.NewLogger(b)
})

it.After(func() {
Expect(os.Unsetenv("BP_LOG_LEVEL")).To(Succeed())
})

it("configures debug", func() {
Expect(l.IsDebugEnabled()).To(BeTrue())
})
})

context("with debug disabled", func() {
it.Before(func() {
l = poet.NewLoggerWithOptions(b)
Expand Down

0 comments on commit d29fc72

Please sign in to comment.