Skip to content

Commit

Permalink
make logger writers public (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frankie G-J authored Feb 9, 2022
1 parent 8f080ea commit 02183b6
Showing 1 changed file with 19 additions and 19 deletions.
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

0 comments on commit 02183b6

Please sign in to comment.