diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-22 20:10:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:16:44 +0800 |
commit | d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch) | |
tree | 17c93170551d3eeabe2935de1765f157007f0dc2 /swarm/services | |
parent | 47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff) | |
download | dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip |
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'swarm/services')
-rw-r--r-- | swarm/services/swap/swap.go | 27 | ||||
-rw-r--r-- | swarm/services/swap/swap/swap.go | 27 |
2 files changed, 26 insertions, 28 deletions
diff --git a/swarm/services/swap/swap.go b/swarm/services/swap/swap.go index f72036d72..eb21a598d 100644 --- a/swarm/services/swap/swap.go +++ b/swarm/services/swap/swap.go @@ -31,8 +31,7 @@ import ( "github.com/ethereum/go-ethereum/contracts/chequebook/contract" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/swarm/services/swap/swap" "golang.org/x/net/context" ) @@ -132,19 +131,19 @@ func NewSwap(local *SwapParams, remote *SwapProfile, backend chequebook.Backend, // TODO: monitoring a chequebooks events ok, err = chequebook.ValidateCode(ctx, backend, remote.Contract) if !ok { - glog.V(logger.Info).Infof("invalid contract %v for peer %v: %v)", remote.Contract.Hex()[:8], proto, err) + log.Info(fmt.Sprintf("invalid contract %v for peer %v: %v)", remote.Contract.Hex()[:8], proto, err)) } else { // remote contract valid, create inbox in, err = chequebook.NewInbox(local.privateKey, remote.Contract, local.Beneficiary, crypto.ToECDSAPub(common.FromHex(remote.PublicKey)), backend) if err != nil { - glog.V(logger.Warn).Infof("unable to set up inbox for chequebook contract %v for peer %v: %v)", remote.Contract.Hex()[:8], proto, err) + log.Warn(fmt.Sprintf("unable to set up inbox for chequebook contract %v for peer %v: %v)", remote.Contract.Hex()[:8], proto, err)) } } // check if local chequebook contract is valid ok, err = chequebook.ValidateCode(ctx, backend, local.Contract) if !ok { - glog.V(logger.Warn).Infof("unable to set up outbox for peer %v: chequebook contract (owner: %v): %v)", proto, local.owner.Hex(), err) + log.Warn(fmt.Sprintf("unable to set up outbox for peer %v: chequebook contract (owner: %v): %v)", proto, local.owner.Hex(), err)) } else { out = chequebook.NewOutbox(local.Chequebook(), remote.Beneficiary) } @@ -172,7 +171,7 @@ func NewSwap(local *SwapParams, remote *SwapProfile, backend chequebook.Backend, } else { sell = "selling to peer disabled" } - glog.V(logger.Warn).Infof("SWAP arrangement with <%v>: %v; %v)", proto, buy, sell) + log.Warn(fmt.Sprintf("SWAP arrangement with <%v>: %v; %v)", proto, buy, sell)) return } @@ -217,13 +216,13 @@ func (self *SwapParams) deployChequebook(ctx context.Context, backend chequebook opts.Value = self.AutoDepositBuffer opts.Context = ctx - glog.V(logger.Info).Infof("Deploying new chequebook (owner: %v)", opts.From.Hex()) + log.Info(fmt.Sprintf("Deploying new chequebook (owner: %v)", opts.From.Hex())) contract, err := deployChequebookLoop(opts, backend) if err != nil { - glog.V(logger.Error).Infof("unable to deploy new chequebook: %v", err) + log.Error(fmt.Sprintf("unable to deploy new chequebook: %v", err)) return err } - glog.V(logger.Info).Infof("new chequebook deployed at %v (owner: %v)", contract.Hex(), opts.From.Hex()) + log.Info(fmt.Sprintf("new chequebook deployed at %v (owner: %v)", contract.Hex(), opts.From.Hex())) // need to save config at this point self.lock.Lock() @@ -231,7 +230,7 @@ func (self *SwapParams) deployChequebook(ctx context.Context, backend chequebook err = self.newChequebookFromContract(path, backend) self.lock.Unlock() if err != nil { - glog.V(logger.Warn).Infof("error initialising cheque book (owner: %v): %v", opts.From.Hex(), err) + log.Warn(fmt.Sprintf("error initialising cheque book (owner: %v): %v", opts.From.Hex(), err)) } return err } @@ -244,11 +243,11 @@ func deployChequebookLoop(opts *bind.TransactOpts, backend chequebook.Backend) ( time.Sleep(chequebookDeployDelay) } if _, tx, _, err = contract.DeployChequebook(opts, backend); err != nil { - glog.V(logger.Warn).Infof("can't send chequebook deploy tx (try %d): %v", try, err) + log.Warn(fmt.Sprintf("can't send chequebook deploy tx (try %d): %v", try, err)) continue } if addr, err = bind.WaitDeployed(opts.Context, backend, tx); err != nil { - glog.V(logger.Warn).Infof("chequebook deploy error (try %d): %v", try, err) + log.Warn(fmt.Sprintf("chequebook deploy error (try %d): %v", try, err)) continue } return addr, nil @@ -271,13 +270,13 @@ func (self *SwapParams) newChequebookFromContract(path string, backend chequeboo if err != nil { self.chbook, err = chequebook.NewChequebook(chbookpath, self.Contract, self.privateKey, backend) if err != nil { - glog.V(logger.Warn).Infof("unable to initialise chequebook (owner: %v): %v", self.owner.Hex(), err) + log.Warn(fmt.Sprintf("unable to initialise chequebook (owner: %v): %v", self.owner.Hex(), err)) return fmt.Errorf("unable to initialise chequebook (owner: %v): %v", self.owner.Hex(), err) } } self.chbook.AutoDeposit(self.AutoDepositInterval, self.AutoDepositThreshold, self.AutoDepositBuffer) - glog.V(logger.Info).Infof("auto deposit ON for %v -> %v: interval = %v, threshold = %v, buffer = %v)", crypto.PubkeyToAddress(*(self.publicKey)).Hex()[:8], self.Contract.Hex()[:8], self.AutoDepositInterval, self.AutoDepositThreshold, self.AutoDepositBuffer) + log.Info(fmt.Sprintf("auto deposit ON for %v -> %v: interval = %v, threshold = %v, buffer = %v)", crypto.PubkeyToAddress(*(self.publicKey)).Hex()[:8], self.Contract.Hex()[:8], self.AutoDepositInterval, self.AutoDepositThreshold, self.AutoDepositBuffer)) return nil } diff --git a/swarm/services/swap/swap/swap.go b/swarm/services/swap/swap/swap.go index 9d5da7c3a..d04194960 100644 --- a/swarm/services/swap/swap/swap.go +++ b/swarm/services/swap/swap/swap.go @@ -23,8 +23,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) // SwAP Swarm Accounting Protocol with @@ -130,7 +129,7 @@ func (self *Swap) SetRemote(remote *Profile) { self.Buys = false } - glog.V(logger.Debug).Infof("<%v> remote profile set: pay at: %v, drop at: %v, buy at: %v, sell at: %v", self.proto, remote.PayAt, remote.DropAt, remote.BuyAt, remote.SellAt) + log.Debug(fmt.Sprintf("<%v> remote profile set: pay at: %v, drop at: %v, buy at: %v, sell at: %v", self.proto, remote.PayAt, remote.DropAt, remote.BuyAt, remote.SellAt)) } @@ -148,15 +147,15 @@ func (self *Swap) setParams(local *Params) { if self.Sells { self.In.AutoCash(local.AutoCashInterval, local.AutoCashThreshold) - glog.V(logger.Info).Infof("<%v> set autocash to every %v, max uncashed limit: %v", self.proto, local.AutoCashInterval, local.AutoCashThreshold) + log.Info(fmt.Sprintf("<%v> set autocash to every %v, max uncashed limit: %v", self.proto, local.AutoCashInterval, local.AutoCashThreshold)) } else { - glog.V(logger.Info).Infof("<%v> autocash off (not selling)", self.proto) + log.Info(fmt.Sprintf("<%v> autocash off (not selling)", self.proto)) } if self.Buys { self.Out.AutoDeposit(local.AutoDepositInterval, local.AutoDepositThreshold, local.AutoDepositBuffer) - glog.V(logger.Info).Infof("<%v> set autodeposit to every %v, pay at: %v, buffer: %v", self.proto, local.AutoDepositInterval, local.AutoDepositThreshold, local.AutoDepositBuffer) + log.Info(fmt.Sprintf("<%v> set autodeposit to every %v, pay at: %v, buffer: %v", self.proto, local.AutoDepositInterval, local.AutoDepositThreshold, local.AutoDepositBuffer)) } else { - glog.V(logger.Info).Infof("<%v> autodeposit off (not buying)", self.proto) + log.Info(fmt.Sprintf("<%v> autodeposit off (not buying)", self.proto)) } } @@ -168,16 +167,16 @@ func (self *Swap) Add(n int) error { self.lock.Lock() self.balance += n if !self.Sells && self.balance > 0 { - glog.V(logger.Detail).Infof("<%v> remote peer cannot have debt (balance: %v)", self.proto, self.balance) + log.Trace(fmt.Sprintf("<%v> remote peer cannot have debt (balance: %v)", self.proto, self.balance)) self.proto.Drop() return fmt.Errorf("[SWAP] <%v> remote peer cannot have debt (balance: %v)", self.proto, self.balance) } if !self.Buys && self.balance < 0 { - glog.V(logger.Detail).Infof("<%v> we cannot have debt (balance: %v)", self.proto, self.balance) + log.Trace(fmt.Sprintf("<%v> we cannot have debt (balance: %v)", self.proto, self.balance)) return fmt.Errorf("[SWAP] <%v> we cannot have debt (balance: %v)", self.proto, self.balance) } if self.balance >= int(self.local.DropAt) { - glog.V(logger.Detail).Infof("<%v> remote peer has too much debt (balance: %v, disconnect threshold: %v)", self.proto, self.balance, self.local.DropAt) + log.Trace(fmt.Sprintf("<%v> remote peer has too much debt (balance: %v, disconnect threshold: %v)", self.proto, self.balance, self.local.DropAt)) self.proto.Drop() return fmt.Errorf("[SWAP] <%v> remote peer has too much debt (balance: %v, disconnect threshold: %v)", self.proto, self.balance, self.local.DropAt) } else if self.balance <= -int(self.remote.PayAt) { @@ -201,9 +200,9 @@ func (self *Swap) send() { amount.Mul(amount, self.remote.SellAt) promise, err := self.Out.Issue(amount) if err != nil { - glog.V(logger.Warn).Infof("<%v> cannot issue cheque (amount: %v, channel: %v): %v", self.proto, amount, self.Out, err) + log.Warn(fmt.Sprintf("<%v> cannot issue cheque (amount: %v, channel: %v): %v", self.proto, amount, self.Out, err)) } else { - glog.V(logger.Warn).Infof("<%v> cheque issued (amount: %v, channel: %v)", self.proto, amount, self.Out) + log.Warn(fmt.Sprintf("<%v> cheque issued (amount: %v, channel: %v)", self.proto, amount, self.Out)) self.proto.Pay(-self.balance, promise) self.balance = 0 } @@ -229,13 +228,13 @@ func (self *Swap) Receive(units int, promise Promise) error { return fmt.Errorf("invalid amount: %v = %v * %v (units sent in msg * agreed sale unit price) != %v (signed in cheque)", price, units, self.local.SellAt, amount) } if err != nil { - glog.V(logger.Detail).Infof("<%v> invalid promise (amount: %v, channel: %v): %v", self.proto, amount, self.In, err) + log.Trace(fmt.Sprintf("<%v> invalid promise (amount: %v, channel: %v): %v", self.proto, amount, self.In, err)) return err } // credit remote peer with units self.Add(-units) - glog.V(logger.Detail).Infof("<%v> received promise (amount: %v, channel: %v): %v", self.proto, amount, self.In, promise) + log.Trace(fmt.Sprintf("<%v> received promise (amount: %v, channel: %v): %v", self.proto, amount, self.In, promise)) return nil } |