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