Skip to content

Commit

Permalink
Add a WithLevel function to scribe.Emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Wigmore authored and ryanmoran committed Jan 7, 2022
1 parent 14956ac commit b0348e1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scribe/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func NewEmitter(output io.Writer) Emitter {
}
}

// WithLevel takes in a log level string and configures the underlying Logger
// log level. To enable debug logging the log level must be set to "DEBUG".
func (e Emitter) WithLevel(level string) Emitter {
e.Logger = e.Logger.WithLevel(level)
return e
}

// SelectedDependency takes in a buildpack plan entry, a postal dependency, and
// the current time, and prints out a message giving the name and version of
// the dependency as well as the source of the request for that given
Expand Down
32 changes: 32 additions & 0 deletions scribe/emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,38 @@ func testEmitter(t *testing.T, context spec.G, it spec.S) {
})
})

context("WithLevel", func() {
context("default", func() {
it("output includes debug level logs", func() {
emitter.Title("non-debug title")
emitter.Debug.Title("debug title")

Expect(buffer.String()).To(ContainLines(
"non-debug title",
))
Expect(buffer.String()).ToNot(ContainLines(
"debug title",
))
})
})

context("DEBUG", func() {
it.Before(func() {
emitter = emitter.WithLevel("DEBUG")
})

it("output includes debug level logs", func() {
emitter.Title("non-debug title")
emitter.Debug.Title("debug title")

Expect(buffer.String()).To(ContainLines(
"non-debug title",
"debug title",
))
})
})
})

context("Candidates", func() {
it("logs the candidate entries", func() {
emitter.Candidates([]packit.BuildpackPlanEntry{
Expand Down

0 comments on commit b0348e1

Please sign in to comment.