Skip to content

Commit

Permalink
misc: add debug output(#master)
Browse files Browse the repository at this point in the history
  • Loading branch information
OhYee committed Jan 21, 2020
1 parent 6b9ae21 commit abf372d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions server/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ package server
// LogCallbackType callback when output log
type LogCallbackType func(format string, args ...interface{})

// DebugCallbackType callback when output debug data
type DebugCallbackType func(format string, args ...interface{})

// ErrCallbackType callback when error occurs
type ErrCallbackType func(err error)

// Singleton Pattern
var (
logCallback = func(format string, args ...interface{}) {}
errCallback = func(err error) {}
logCallback = func(format string, args ...interface{}) {}
debugCallback = func(format string, args ...interface{}) {}
errCallback = func(err error) {}
)

// SetLogCallback set callback when output log
func SetLogCallback(callback LogCallbackType) {
logCallback = callback
}

// SetDebugCallback set callback when output log
func SetDebugCallback(callback DebugCallbackType) {
debugCallback = callback
}

// SetErrCallback set callback when error occurs
func SetErrCallback(callback ErrCallbackType) {
errCallback = callback
Expand All @@ -27,6 +36,11 @@ func Log(format string, args ...interface{}) {
logCallback(format, args...)
}

// Debug make a debug output
func Debug(format string, args ...interface{}) {
debugCallback(format, args...)
}

// Err make a error output
func Err(err error) {
errCallback(err)
Expand Down

0 comments on commit abf372d

Please sign in to comment.