Add minimalistic Logger interface
This commit is contained in:
parent
154c493b64
commit
c2f8c05bb5
11
daemon.go
11
daemon.go
|
@ -3,7 +3,6 @@ package satan
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -48,7 +47,7 @@ type BaseDaemon struct {
|
|||
self Daemon
|
||||
name string
|
||||
queue chan<- *task
|
||||
logger *log.Logger
|
||||
logger Logger
|
||||
panicHandler PanicHandler
|
||||
subscriber Subscriber
|
||||
publisher Publisher
|
||||
|
@ -128,10 +127,10 @@ func (d *BaseDaemon) Publish(msg []byte) {
|
|||
func (d *BaseDaemon) LimitRate(times int, per time.Duration) {
|
||||
rate := float64(time.Second) / float64(per) * float64(times)
|
||||
if rate <= 0 {
|
||||
d.logger.Println("Daemon %s processing rate was limited to %d. Using 1 instead", d.base(), rate)
|
||||
d.Logf("Daemon %s processing rate was limited to %d. Using 1 instead", d.base(), rate)
|
||||
rate = 1.0
|
||||
}
|
||||
d.logger.Printf("Daemon %s processing rate is limited to %.2f ops/s", d.base(), rate)
|
||||
d.Logf("Daemon %s processing rate is limited to %.2f ops/s", d.base(), rate)
|
||||
d.limit = ratelimit.NewBucketWithRate(rate, 1)
|
||||
}
|
||||
|
||||
|
@ -157,12 +156,16 @@ func (d *BaseDaemon) Continue() bool {
|
|||
}
|
||||
|
||||
func (d *BaseDaemon) Log(v ...interface{}) {
|
||||
if d.logger != nil {
|
||||
d.logger.Println(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *BaseDaemon) Logf(format string, v ...interface{}) {
|
||||
if d.logger != nil {
|
||||
d.logger.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *BaseDaemon) Shutdown() {}
|
||||
|
||||
|
|
8
satan.go
8
satan.go
|
@ -16,7 +16,7 @@ type Satan struct {
|
|||
Subscriber Subscriber
|
||||
Publisher Publisher
|
||||
DaemonStats stats.Publisher
|
||||
Logger *log.Logger
|
||||
Logger Logger
|
||||
NumWorkers int
|
||||
|
||||
daemons []Daemon
|
||||
|
@ -51,6 +51,12 @@ type Publisher interface {
|
|||
Close()
|
||||
}
|
||||
|
||||
// Logger is the interface that implements minimal logging functions.
|
||||
type Logger interface {
|
||||
Printf(format string, v ...interface{})
|
||||
Println(v ...interface{})
|
||||
}
|
||||
|
||||
type task struct {
|
||||
daemon Daemon
|
||||
actor Actor
|
||||
|
|
Loading…
Reference in New Issue