Use btclog for logging.
This commit is contained in:
parent
8a19f269ca
commit
f7f51a1e43
1 changed files with 13 additions and 8 deletions
21
log.go
21
log.go
|
@ -6,14 +6,14 @@ package btcchain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/conformal/seelog"
|
"github.com/conformal/btclog"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// log is a logger that is initialized with no output filters. This
|
// log is a logger that is initialized with no output filters. This
|
||||||
// means the package will not perform any logging by default until the caller
|
// means the package will not perform any logging by default until the caller
|
||||||
// requests it.
|
// requests it.
|
||||||
var log seelog.LoggerInterface
|
var log btclog.Logger
|
||||||
|
|
||||||
// The default amount of logging is none.
|
// The default amount of logging is none.
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -23,26 +23,31 @@ func init() {
|
||||||
// DisableLog disables all library log output. Logging output is disabled
|
// DisableLog disables all library log output. Logging output is disabled
|
||||||
// by default until either UseLogger or SetLogWriter are called.
|
// by default until either UseLogger or SetLogWriter are called.
|
||||||
func DisableLog() {
|
func DisableLog() {
|
||||||
log = seelog.Disabled
|
log = btclog.Disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseLogger uses a specified Logger to output package logging info.
|
// UseLogger uses a specified Logger to output package logging info.
|
||||||
// This should be used in preference to SetLogWriter if the caller is also
|
// This should be used in preference to SetLogWriter if the caller is also
|
||||||
// using seelog.
|
// using btclog.
|
||||||
func UseLogger(logger seelog.LoggerInterface) {
|
func UseLogger(logger btclog.Logger) {
|
||||||
log = logger
|
log = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLogWriter uses a specified io.Writer to output package logging info.
|
// SetLogWriter uses a specified io.Writer to output package logging info.
|
||||||
// This allows a caller to direct package logging output without needing a
|
// This allows a caller to direct package logging output without needing a
|
||||||
// dependency on seelog. If the caller is also using seelog, UseLogger should
|
// dependency on seelog. If the caller is also using btclog, UseLogger should
|
||||||
// be used instead.
|
// be used instead.
|
||||||
func SetLogWriter(w io.Writer) error {
|
func SetLogWriter(w io.Writer, level string) error {
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return errors.New("nil writer")
|
return errors.New("nil writer")
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := seelog.LoggerFromWriterWithMinLevel(w, seelog.TraceLvl)
|
lvl, ok := btclog.LogLevelFromString(level)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("invalid log level")
|
||||||
|
}
|
||||||
|
|
||||||
|
l, err := btclog.NewLoggerFromWriter(w, lvl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue