Use btclog for logging.
This commit is contained in:
parent
d226968472
commit
3bc401fed1
4 changed files with 21 additions and 16 deletions
|
@ -8,12 +8,12 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
|
"github.com/conformal/btclog"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/goleveldb/leveldb"
|
"github.com/conformal/goleveldb/leveldb"
|
||||||
"github.com/conformal/goleveldb/leveldb/cache"
|
"github.com/conformal/goleveldb/leveldb/cache"
|
||||||
"github.com/conformal/goleveldb/leveldb/opt"
|
"github.com/conformal/goleveldb/leveldb/opt"
|
||||||
"github.com/conformal/seelog"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,7 @@ const (
|
||||||
dbMaxTransMem = 64 * 1024 * 1024 // 64 MB
|
dbMaxTransMem = 64 * 1024 * 1024 // 64 MB
|
||||||
)
|
)
|
||||||
|
|
||||||
var log seelog.LoggerInterface = seelog.Disabled
|
var log = btclog.Disabled
|
||||||
|
|
||||||
type tTxInsertData struct {
|
type tTxInsertData struct {
|
||||||
txsha *btcwire.ShaHash
|
txsha *btcwire.ShaHash
|
||||||
|
|
25
log.go
25
log.go
|
@ -6,14 +6,14 @@ package btcdb
|
||||||
|
|
||||||
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() {
|
||||||
|
@ -21,28 +21,33 @@ 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 UserLogger 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
|
||||||
}
|
}
|
||||||
|
@ -52,6 +57,6 @@ func SetLogWriter(w io.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLog returns the currently active logger.
|
// GetLog returns the currently active logger.
|
||||||
func GetLog() seelog.LoggerInterface {
|
func GetLog() btclog.Logger {
|
||||||
return log
|
return log
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ package memdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
"github.com/conformal/seelog"
|
"github.com/conformal/btclog"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = seelog.Disabled
|
var log = btclog.Disabled
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
driver := btcdb.DriverDB{DbType: "memdb", Create: CreateDB, Open: OpenDB}
|
driver := btcdb.DriverDB{DbType: "memdb", Create: CreateDB, Open: OpenDB}
|
||||||
|
|
|
@ -8,9 +8,9 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
|
"github.com/conformal/btclog"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/seelog"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -88,7 +88,7 @@ var txqueries []string = []string{
|
||||||
txtmpExistsShaStmt: "SELECT blockid FROM txtmp WHERE key = ?;",
|
txtmpExistsShaStmt: "SELECT blockid FROM txtmp WHERE key = ?;",
|
||||||
}
|
}
|
||||||
|
|
||||||
var log seelog.LoggerInterface = seelog.Disabled
|
var log = btclog.Disabled
|
||||||
|
|
||||||
type tBlockInsertData struct {
|
type tBlockInsertData struct {
|
||||||
sha btcwire.ShaHash
|
sha btcwire.ShaHash
|
||||||
|
|
Loading…
Reference in a new issue