Skip to content

Commit

Permalink
feat: logger
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Sep 24, 2019
1 parent fc86742 commit cf17564
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions freesia.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package freesia
import (
"context"
"fmt"
"os"

"github.com/xiaojiaoyu100/lizard/mass"

"github.com/go-redis/redis"
"github.com/sirupsen/logrus"
"github.com/vmihailenco/msgpack"
"github.com/xiaojiaoyu100/curlew"
"github.com/xiaojiaoyu100/freesia/entry"
Expand All @@ -17,7 +19,8 @@ type Freesia struct {
store Store
cache *roc.Cache
dispatcher *curlew.Dispatcher
pubsub *redis.PubSub
pubSub *redis.PubSub
logger *logrus.Logger
}

func New(store Store, setters ...Setter) (*Freesia, error) {
Expand All @@ -44,10 +47,18 @@ func New(store Store, setters ...Setter) (*Freesia, error) {
return nil, err
}

f.pubsub = f.store.Subscribe(channel)
f.pubSub = f.store.Subscribe(channel)

f.sub()

logger := logrus.New()
logger.SetLevel(logrus.InfoLevel)
logger.SetOutput(os.Stdout)
logger.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05",
})
f.logger = logger

return f, nil
}

Expand Down Expand Up @@ -233,7 +244,7 @@ func (f *Freesia) Pub(keys ...string) error {

func (f *Freesia) sub() {
go func() {
for message := range f.pubsub.Channel() {
for message := range f.pubSub.Channel() {
job := curlew.NewJob()
job.Arg = message
job.Fn = func(ctx context.Context, arg interface{}) error {
Expand Down

0 comments on commit cf17564

Please sign in to comment.