Skip to content

Commit

Permalink
Expose renderer + SimpleRenderer RenderRawMessage method (#22)
Browse files Browse the repository at this point in the history
* Annotations support + SimpleRenderer RenderRawMessage method

* Remove annotations and expose the renderer
  • Loading branch information
edigaryev authored Apr 11, 2022
1 parent 1807864 commit 72e2916
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Logger struct {
level LogLevel
scopes []string
entriesChannel chan *genericLogEntry
renderer LogRendered
}

type FinishType int
Expand All @@ -30,11 +31,16 @@ func NewLogger(level LogLevel, renderer LogRendered) *Logger {
logger := &Logger{
level: level,
entriesChannel: make(chan *genericLogEntry),
renderer: renderer,
}
go logger.streamEntries(renderer)
return logger
}

func (logger *Logger) Renderer() LogRendered {
return logger.renderer
}

func (logger *Logger) Scoped(scope string) *Logger {
result := &Logger{
level: logger.level,
Expand Down
2 changes: 2 additions & 0 deletions renderers/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type InteractiveRenderer struct {
currentFrameLines []string
drawLock sync.Mutex
terminalHeight int

StubRenderer
}

func NewInteractiveRenderer(out *os.File, rendererConfig *config.InteractiveRendererConfig) *InteractiveRenderer {
Expand Down
1 change: 1 addition & 0 deletions renderers/internal/console/helpers.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package console
Expand Down
14 changes: 8 additions & 6 deletions renderers/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type SimpleRenderer struct {
out io.Writer
colors *terminal.ColorSchema
startTimes map[string]time.Time

StubRenderer
}

func NewSimpleRenderer(out io.Writer, colors *terminal.ColorSchema) *SimpleRenderer {
Expand Down Expand Up @@ -44,7 +46,7 @@ func (r SimpleRenderer) RenderScopeStarted(entry *echelon.LogScopeStarted) {
r.startTimes[timeKey] = time.Now()
lastScope := scopes[level-1]
message := terminal.GetColoredText(r.colors.NeutralColor, fmt.Sprintf("Started %s", quotedIfNeeded(lastScope)))
r.renderEntry(message)
r.RenderRawMessage(message)
}

func (r SimpleRenderer) RenderScopeFinished(entry *echelon.LogScopeFinished) {
Expand All @@ -66,23 +68,23 @@ func (r SimpleRenderer) RenderScopeFinished(entry *echelon.LogScopeFinished) {
case echelon.FinishTypeSucceeded:
message := fmt.Sprintf("%s succeeded in %s!", quotedIfNeeded(lastScope), formatedDuration)
coloredMessage := terminal.GetColoredText(r.colors.SuccessColor, message)
r.renderEntry(coloredMessage)
r.RenderRawMessage(coloredMessage)
case echelon.FinishTypeFailed:
message := fmt.Sprintf("%s failed in %s!", quotedIfNeeded(lastScope), formatedDuration)
coloredMessage := terminal.GetColoredText(r.colors.FailureColor, message)
r.renderEntry(coloredMessage)
r.RenderRawMessage(coloredMessage)
case echelon.FinishTypeSkipped:
message := fmt.Sprintf("%s skipped in %s!", quotedIfNeeded(lastScope), formatedDuration)
coloredMessage := terminal.GetColoredText(r.colors.NeutralColor, message)
r.renderEntry(coloredMessage)
r.RenderRawMessage(coloredMessage)
}
}

func (r SimpleRenderer) RenderMessage(entry *echelon.LogEntryMessage) {
r.renderEntry(entry.GetMessage())
r.RenderRawMessage(entry.GetMessage())
}

func (r SimpleRenderer) renderEntry(message string) {
func (r SimpleRenderer) RenderRawMessage(message string) {
_, _ = r.out.Write([]byte(message + "\n"))
}

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

import "github.com/cirruslabs/echelon"

type StubRenderer struct{}

func (*StubRenderer) RenderScopeStarted(entry *echelon.LogScopeStarted) {}

func (*StubRenderer) RenderScopeFinished(entry *echelon.LogScopeFinished) {}

func (*StubRenderer) RenderMessage(entry *echelon.LogEntryMessage) {}

0 comments on commit 72e2916

Please sign in to comment.