Commit 6f1789fd authored by Jeromy's avatar Jeromy Committed by Juan Batiz-Benet

update logging in multiple packages

parent 29a24c8b
......@@ -7,12 +7,15 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/op/go-logging"
blocks "github.com/jbenet/go-ipfs/blocks"
exchange "github.com/jbenet/go-ipfs/exchange"
u "github.com/jbenet/go-ipfs/util"
)
var log = logging.MustGetLogger("blockservice")
// BlockService is a block datastore.
// It uses an internal `datastore.Datastore` instance to store values.
type BlockService struct {
......@@ -26,7 +29,7 @@ func NewBlockService(d ds.Datastore, rem exchange.Interface) (*BlockService, err
return nil, fmt.Errorf("BlockService requires valid datastore")
}
if rem == nil {
u.DErr("Caution: blockservice running in local (offline) mode.\n")
log.Warning("blockservice running in local (offline) mode.")
}
return &BlockService{Datastore: d, Remote: rem}, nil
}
......@@ -35,7 +38,7 @@ func NewBlockService(d ds.Datastore, rem exchange.Interface) (*BlockService, err
func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
k := b.Key()
dsk := ds.NewKey(string(k))
u.DOut("storing [%s] in datastore\n", k.Pretty())
log.Debug("storing [%s] in datastore", k.Pretty())
// TODO(brian): define a block datastore with a Put method which accepts a
// block parameter
err := s.Datastore.Put(dsk, b.Data)
......@@ -52,11 +55,11 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
u.DOut("BlockService GetBlock: '%s'\n", k.Pretty())
log.Debug("BlockService GetBlock: '%s'", k.Pretty())
dsk := ds.NewKey(string(k))
datai, err := s.Datastore.Get(dsk)
if err == nil {
u.DOut("Blockservice: Got data in datastore.\n")
log.Debug("Blockservice: Got data in datastore.")
bdata, ok := datai.([]byte)
if !ok {
return nil, fmt.Errorf("data associated with %s is not a []byte", k)
......@@ -66,7 +69,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
Data: bdata,
}, nil
} else if err == ds.ErrNotFound && s.Remote != nil {
u.DOut("Blockservice: Searching bitswap.\n")
log.Debug("Blockservice: Searching bitswap.")
ctx, _ := context.WithTimeout(context.TODO(), 5*time.Second)
blk, err := s.Remote.Block(ctx, k)
if err != nil {
......@@ -74,7 +77,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
}
return blk, nil
} else {
u.DOut("Blockservice GetBlock: Not found.\n")
log.Debug("Blockservice GetBlock: Not found.")
return nil, u.ErrNotFound
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment