mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loop+cmd: extract types into swap module
This commit is contained in:
parent
7a1680d7d6
commit
69f2af9fdc
13 changed files with 104 additions and 89 deletions
45
log.go
45
log.go
|
|
@ -1,11 +1,9 @@
|
|||
package loop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
|
||||
// log is a logger that is initialized with no output filters. This
|
||||
|
|
@ -24,46 +22,3 @@ func (logWriter) Write(p []byte) (n int, err error) {
|
|||
os.Stdout.Write(p)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// SwapLog logs with a short swap hash prefix.
|
||||
type SwapLog struct {
|
||||
// Logger is the underlying based logger.
|
||||
Logger btclog.Logger
|
||||
|
||||
// Hash is the hash the identifies the target swap.
|
||||
Hash lntypes.Hash
|
||||
}
|
||||
|
||||
// Infof formats message according to format specifier and writes to
|
||||
// log with LevelInfo.
|
||||
func (s *SwapLog) Infof(format string, params ...interface{}) {
|
||||
s.Logger.Infof(
|
||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||
params...,
|
||||
)
|
||||
}
|
||||
|
||||
// Warnf formats message according to format specifier and writes to
|
||||
// to log with LevelError.
|
||||
func (s *SwapLog) Warnf(format string, params ...interface{}) {
|
||||
s.Logger.Warnf(
|
||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||
params...,
|
||||
)
|
||||
}
|
||||
|
||||
// Errorf formats message according to format specifier and writes to
|
||||
// to log with LevelError.
|
||||
func (s *SwapLog) Errorf(format string, params ...interface{}) {
|
||||
s.Logger.Errorf(
|
||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||
params...,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
// ShortHash returns a shortened version of the hash suitable for use in
|
||||
// logging.
|
||||
func ShortHash(hash *lntypes.Hash) string {
|
||||
return hash.String()[:6]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue