-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from seqsense/control-debug-output
Control debug output by Option.Debug
- Loading branch information
Showing
5 changed files
with
106 additions
and
17 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,34 @@ | ||
package awsiotdev | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
var ( | ||
// Backend function of debug print output. This can be replaced by custom logger. | ||
DebugPrintBackend func(...interface{}) = log.Print | ||
// Backend function of debug printf output. This can be replaced by custom logger. | ||
DebugPrintfBackend func(string, ...interface{}) = log.Printf | ||
// Backend function of debug println output. This can be replaced by custom logger. | ||
DebugPrintlnBackend func(...interface{}) = log.Println | ||
) | ||
|
||
type debugOut struct { | ||
enable bool | ||
} | ||
|
||
func (s *debugOut) print(a ...interface{}) { | ||
if s.enable { | ||
DebugPrintBackend(a...) | ||
} | ||
} | ||
func (s *debugOut) printf(format string, a ...interface{}) { | ||
if s.enable { | ||
DebugPrintfBackend(format, a...) | ||
} | ||
} | ||
func (s *debugOut) println(a ...interface{}) { | ||
if s.enable { | ||
DebugPrintlnBackend(a...) | ||
} | ||
} |
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 awsiotdev | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
) | ||
|
||
func Example_debugOut_print() { | ||
DebugPrintBackend = func(a ...interface{}) { | ||
fmt.Print(a...) | ||
} | ||
|
||
s := &debugOut{true} | ||
s.print("Test1:", true) | ||
s = &debugOut{false} | ||
s.print("Test2:", false) | ||
|
||
DebugPrintBackend = log.Print | ||
|
||
// Output: | ||
// Test1:true | ||
} | ||
|
||
func Example_debugOut_printf() { | ||
DebugPrintfBackend = func(format string, a ...interface{}) { | ||
fmt.Printf(format, a...) | ||
} | ||
|
||
s := &debugOut{true} | ||
s.printf("Formatted value 1 (%d)", 10) | ||
s = &debugOut{false} | ||
s.printf("Formatted value 2 (%d)", 11) | ||
|
||
DebugPrintfBackend = log.Printf | ||
|
||
// Output: | ||
// Formatted value 1 (10) | ||
} | ||
|
||
func Example_debugOut_println() { | ||
DebugPrintlnBackend = func(a ...interface{}) { | ||
fmt.Println(a...) | ||
} | ||
|
||
s := &debugOut{true} | ||
s.println(errors.New("Error string 1")) | ||
s = &debugOut{false} | ||
s.println(errors.New("Error string 2")) | ||
|
||
DebugPrintlnBackend = log.Println | ||
|
||
// Output: | ||
// Error string 1 | ||
} |
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