Use btclog for logging.

This commit is contained in:
Dave Collins 2013-11-21 09:48:16 -06:00
parent d226968472
commit 3bc401fed1
4 changed files with 21 additions and 16 deletions

View file

@ -8,12 +8,12 @@ import (
"encoding/binary"
"fmt"
"github.com/conformal/btcdb"
"github.com/conformal/btclog"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
"github.com/conformal/goleveldb/leveldb"
"github.com/conformal/goleveldb/leveldb/cache"
"github.com/conformal/goleveldb/leveldb/opt"
"github.com/conformal/seelog"
"os"
"sync"
)
@ -24,7 +24,7 @@ const (
dbMaxTransMem = 64 * 1024 * 1024 // 64 MB
)
var log seelog.LoggerInterface = seelog.Disabled
var log = btclog.Disabled
type tTxInsertData struct {
txsha *btcwire.ShaHash

25
log.go
View file

@ -6,14 +6,14 @@ package btcdb
import (
"errors"
"github.com/conformal/seelog"
"github.com/conformal/btclog"
"io"
)
// 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
// requests it.
var log seelog.LoggerInterface
var log btclog.Logger
// The default amount of logging is none.
func init() {
@ -21,28 +21,33 @@ func init() {
}
// 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() {
log = seelog.Disabled
log = btclog.Disabled
}
// UseLogger uses a specified Logger to output package logging info.
// This should be used in preference to SetLogWriter if the caller is also
// using seelog.
func UseLogger(logger seelog.LoggerInterface) {
// using btclog.
func UseLogger(logger btclog.Logger) {
log = logger
}
// SetLogWriter uses a specified io.Writer to output package logging info.
// 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.
func SetLogWriter(w io.Writer) error {
func SetLogWriter(w io.Writer, level string) error {
if w == nil {
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 {
return err
}
@ -52,6 +57,6 @@ func SetLogWriter(w io.Writer) error {
}
// GetLog returns the currently active logger.
func GetLog() seelog.LoggerInterface {
func GetLog() btclog.Logger {
return log
}

View file

@ -6,10 +6,10 @@ package memdb
import (
"github.com/conformal/btcdb"
"github.com/conformal/seelog"
"github.com/conformal/btclog"
)
var log = seelog.Disabled
var log = btclog.Disabled
func init() {
driver := btcdb.DriverDB{DbType: "memdb", Create: CreateDB, Open: OpenDB}

View file

@ -8,9 +8,9 @@ import (
"database/sql"
"fmt"
"github.com/conformal/btcdb"
"github.com/conformal/btclog"
"github.com/conformal/btcutil"
"github.com/conformal/btcwire"
"github.com/conformal/seelog"
_ "github.com/mattn/go-sqlite3"
"os"
"sync"
@ -88,7 +88,7 @@ var txqueries []string = []string{
txtmpExistsShaStmt: "SELECT blockid FROM txtmp WHERE key = ?;",
}
var log seelog.LoggerInterface = seelog.Disabled
var log = btclog.Disabled
type tBlockInsertData struct {
sha btcwire.ShaHash