Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose LeveledLogger's Writers #284

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions scribe/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,66 +45,66 @@ func (l Logger) WithLevel(level string) Logger {

// A LeveledLogger provides a standard interface for basic formatted logging.
type LeveledLogger struct {
title io.Writer
process io.Writer
subprocess io.Writer
action io.Writer
detail io.Writer
subdetail io.Writer
TitleWriter io.Writer
ProcessWriter io.Writer
SubprocessWriter io.Writer
ActionWriter io.Writer
DetailWriter io.Writer
SubdetailWriter io.Writer
}

// NewLeveledLogger takes a writer and returns a LeveledLogger that writes to the given
// writer.
func NewLeveledLogger(writer io.Writer) LeveledLogger {
return LeveledLogger{
title: NewWriter(writer),
process: NewWriter(writer, WithIndent(1)),
subprocess: NewWriter(writer, WithIndent(2)),
action: NewWriter(writer, WithIndent(3)),
detail: NewWriter(writer, WithIndent(4)),
subdetail: NewWriter(writer, WithIndent(5)),
TitleWriter: NewWriter(writer),
ProcessWriter: NewWriter(writer, WithIndent(1)),
SubprocessWriter: NewWriter(writer, WithIndent(2)),
ActionWriter: NewWriter(writer, WithIndent(3)),
DetailWriter: NewWriter(writer, WithIndent(4)),
SubdetailWriter: NewWriter(writer, WithIndent(5)),
}
}

// Title takes a string and optional formatting, and prints a formatted string
// with zero levels of indentation.
func (l LeveledLogger) Title(format string, v ...interface{}) {
l.printf(l.title, format, v...)
l.printf(l.TitleWriter, format, v...)
}

// Process takes a string and optional formatting, and prints a formatted string
// with one level of indentation.
func (l LeveledLogger) Process(format string, v ...interface{}) {
l.printf(l.process, format, v...)
l.printf(l.ProcessWriter, format, v...)
}

// Subprocess takes a string and optional formatting, and prints a formatted string
// with two levels of indentation.
func (l LeveledLogger) Subprocess(format string, v ...interface{}) {
l.printf(l.subprocess, format, v...)
l.printf(l.SubprocessWriter, format, v...)
}

// Action takes a string and optional formatting, and prints a formatted string
// with three levels of indentation.
func (l LeveledLogger) Action(format string, v ...interface{}) {
l.printf(l.action, format, v...)
l.printf(l.ActionWriter, format, v...)
}

// Detail takes a string and optional formatting, and prints a formatted string
// with four levels of indentation.
func (l LeveledLogger) Detail(format string, v ...interface{}) {
l.printf(l.detail, format, v...)
l.printf(l.DetailWriter, format, v...)
}

// Subdetail takes a string and optional formatting, and prints a formatted string
// with five levels of indentation.
func (l LeveledLogger) Subdetail(format string, v ...interface{}) {
l.printf(l.subdetail, format, v...)
l.printf(l.SubdetailWriter, format, v...)
}

// Break inserts a line break in the log output
func (l LeveledLogger) Break() {
l.printf(l.title, "\n")
l.printf(l.TitleWriter, "\n")
}

func (l LeveledLogger) printf(writer io.Writer, format string, v ...interface{}) {
Expand Down