From fda40a96826f9915a73545894d855f03d47670c7 Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Wed, 8 Sep 2021 10:29:30 -0400 Subject: [PATCH] new Errorln method and add comments --- cmd/ghcs/output/logger.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/ghcs/output/logger.go b/cmd/ghcs/output/logger.go index 32d05acc8..a2aa68ba1 100644 --- a/cmd/ghcs/output/logger.go +++ b/cmd/ghcs/output/logger.go @@ -5,6 +5,8 @@ import ( "io" ) +// NewLogger returns a Logger that will write to the given stdout/stderr writers. +// Disable the Logger to prevent it from writing to stdout in a TTY environment. func NewLogger(stdout, stderr io.Writer, disabled bool) *Logger { return &Logger{ out: stdout, @@ -13,12 +15,16 @@ func NewLogger(stdout, stderr io.Writer, disabled bool) *Logger { } } +// Logger writes to the given stdout/stderr writers. +// If not enabled, Print functions will noop but Error functions will continue +// to write to the stderr writer. type Logger struct { out io.Writer errout io.Writer enabled bool } +// Print writes the arguments to the stdout writer. func (l *Logger) Print(v ...interface{}) (int, error) { if !l.enabled { return 0, nil @@ -26,6 +32,7 @@ func (l *Logger) Print(v ...interface{}) (int, error) { return fmt.Fprint(l.out, v...) } +// Println writes the arguments to the stdout writer with a newline at the end. func (l *Logger) Println(v ...interface{}) (int, error) { if !l.enabled { return 0, nil @@ -33,6 +40,7 @@ func (l *Logger) Println(v ...interface{}) (int, error) { return fmt.Fprintln(l.out, v...) } +// Printf writes the formatted arguments to the stdout writer. func (l *Logger) Printf(f string, v ...interface{}) (int, error) { if !l.enabled { return 0, nil @@ -40,6 +48,12 @@ func (l *Logger) Printf(f string, v ...interface{}) (int, error) { return fmt.Fprintf(l.out, f, v...) } +// Errorf writes the formatted arguments to the stderr writer. func (l *Logger) Errorf(f string, v ...interface{}) (int, error) { return fmt.Fprintf(l.errout, f, v...) } + +// Errorln writes the arguments to the stderr writer with a newline at the end. +func (l *Logger) Errorln(v ...interface{}) (int, error) { + return fmt.Fprintln(l.errout, v...) +}