Skip to content

Commit

Permalink
use debugLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
dworld committed Nov 12, 2014
1 parent 90c9586 commit ce17bbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const (
)

type Config struct {
EnableDebug bool

CookieSecret string

StaticDir string
Expand Down
17 changes: 17 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ type Logger interface {
Debugf(s string, o ...interface{})
Tracef(s string, o ...interface{})
}

type debugLogger struct {
Logger
enableDebug bool
}

func (l *debugLogger) Debugf(s string, o ...interface{}) {
if l.enableDebug {
l.Logger.Debugf(s, o...)
}
}

func (l *debugLogger) Tracef(s string, o ...interface{}) {
if l.enableDebug {
l.Logger.Tracef(s, o...)
}
}
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewServer(config *Config) *Server {
}
setDefaultConfig(config)
server := &Server{
Logger: logex.NewLogger(1),
Logger: &debugLogger{Logger: logex.NewLogger(1), enableDebug: config.EnableDebug},
Config: config,
}
server.PanicHandler = DefaultPanicHandler
Expand Down

0 comments on commit ce17bbf

Please sign in to comment.