-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve debug log
- Loading branch information
Showing
5 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package writer | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
type logger interface { | ||
Write(b []byte) | ||
Println(args ...interface{}) | ||
Printf(format string, args ...interface{}) | ||
Error(args ...interface{}) | ||
Errorf(format string, args ...interface{}) | ||
} | ||
|
||
type noopLogger struct{} | ||
|
||
type debugLogger struct { | ||
stdout io.Writer | ||
stderr io.Writer | ||
} | ||
|
||
func newDebugLogger() *debugLogger { | ||
return &debugLogger{ | ||
stdout: os.Stdout, | ||
stderr: os.Stderr, | ||
} | ||
} | ||
|
||
func (l *noopLogger) Write(b []byte) {} | ||
func (l *noopLogger) Println(args ...interface{}) {} | ||
func (l *noopLogger) Printf(format string, args ...interface{}) {} | ||
func (l *noopLogger) Error(args ...interface{}) {} | ||
func (l *noopLogger) Errorf(format string, args ...interface{}) {} | ||
|
||
func (l *debugLogger) Write(b []byte) { | ||
fmt.Fprintf(l.stdout, "%s", b) | ||
} | ||
|
||
func (l *debugLogger) Println(args ...interface{}) { | ||
fmt.Fprintln(l.stdout, args...) | ||
} | ||
|
||
func (l *debugLogger) Printf(format string, args ...interface{}) { | ||
fmt.Fprintf(l.stdout, format, args...) | ||
} | ||
|
||
func (l *debugLogger) Error(args ...interface{}) { | ||
fmt.Fprintln(l.stderr, args...) | ||
} | ||
|
||
func (l *debugLogger) Errorf(format string, args ...interface{}) { | ||
fmt.Fprintf(l.stderr, format, args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
package writer | ||
|
||
type noopMutex struct{} | ||
type noopWriter struct{} | ||
|
||
func (*noopMutex) Lock() {} | ||
func (*noopMutex) Unlock() {} | ||
|
||
func (*noopWriter) Write([]byte) (int, error) { | ||
return 0, nil // no-op | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters