Skip to content

Commit

Permalink
add log info switch
Browse files Browse the repository at this point in the history
  • Loading branch information
libi committed Dec 12, 2022
1 parent c239ca5 commit 745603e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dcron.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type Dcron struct {
nodePool *NodePool
running int32

logger interface{ Printf(string, ...interface{}) }
logger interface{ Printf(string, ...interface{}) }
logInfo bool

nodeUpdateDuration time.Duration
hashReplicas int
Expand Down Expand Up @@ -80,7 +81,9 @@ func (d *Dcron) GetLogger() interface{ Printf(string, ...interface{}) } {
}

func (d *Dcron) info(format string, v ...interface{}) {
d.logger.Printf("INFO: "+format, v...)
if d.logInfo {
d.logger.Printf("INFO: "+format, v...)
}
}
func (d *Dcron) err(format string, v ...interface{}) {
d.logger.Printf("ERR: "+format, v...)
Expand Down
7 changes: 7 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func WithLogger(logger interface{ Printf(string, ...interface{}) }) Option {
}
}

// PrintLogInfo set log info level
func WithPrintLogInfo() Option {
return func(dcron *Dcron) {
dcron.logInfo = true
}
}

// WithNodeUpdateDuration set node update duration
func WithNodeUpdateDuration(d time.Duration) Option {
return func(dcron *Dcron) {
Expand Down

0 comments on commit 745603e

Please sign in to comment.