Skip to content

Commit

Permalink
lnd: remove seelog logger
Browse files Browse the repository at this point in the history
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
  • Loading branch information
andrewshvv authored and Roasbeef committed Jun 25, 2017
1 parent c233b88 commit 8fa2b95
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 336 deletions.
32 changes: 2 additions & 30 deletions chainntnfs/log.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package chainntnfs

import (
"errors"
"io"

"github.com/btcsuite/btclog"
)
import "github.com/btcsuite/btclog"

// 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
Expand All @@ -18,7 +13,7 @@ func init() {
}

// DisableLog disables all library log output. Logging output is disabled
// by default until either UseLogger or SetLogWriter are called.
// by default until UseLogger is called.
func DisableLog() {
Log = btclog.Disabled
}
Expand All @@ -29,26 +24,3 @@ func DisableLog() {
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 btclog, UseLogger should
// be used instead.
func SetLogWriter(w io.Writer, level string) error {
if w == nil {
return errors.New("nil writer")
}

lvl, ok := btclog.LogLevelFromString(level)
if !ok {
return errors.New("invalid log level")
}

l, err := btclog.NewLoggerFromWriter(w, lvl)
if err != nil {
return err
}

UseLogger(l)
return nil
}
32 changes: 2 additions & 30 deletions channeldb/log.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package channeldb

import (
"errors"
"io"

"github.com/btcsuite/btclog"
)
import "github.com/btcsuite/btclog"

// 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
Expand All @@ -18,7 +13,7 @@ func init() {
}

// DisableLog disables all library log output. Logging output is disabled
// by default until either UseLogger or SetLogWriter are called.
// by default until UseLogger is called.
func DisableLog() {
log = btclog.Disabled
}
Expand All @@ -29,26 +24,3 @@ func DisableLog() {
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 btclog, UseLogger should
// be used instead.
func SetLogWriter(w io.Writer, level string) error {
if w == nil {
return errors.New("nil writer")
}

lvl, ok := btclog.LogLevelFromString(level)
if !ok {
return errors.New("invalid log level")
}

l, err := btclog.NewLoggerFromWriter(w, lvl)
if err != nil {
return err
}

UseLogger(l)
return nil
}
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func loadConfig() (*config, error) {
registeredChains.primaryChain.String())

// Initialize logging at the default logging level.
initSeelogLogger(filepath.Join(cfg.LogDir, defaultLogFilename))
initLogRotator(filepath.Join(cfg.LogDir, defaultLogFilename))
setLogLevels(defaultLogLevel)

// Parse, validate, and set debug log level(s).
Expand Down
34 changes: 2 additions & 32 deletions discovery/log.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package discovery

import (
"errors"
"io"

"github.com/btcsuite/btclog"
btcwallet "github.com/roasbeef/btcwallet/wallet"
)
import "github.com/btcsuite/btclog"

// 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
Expand All @@ -19,7 +13,7 @@ func init() {
}

// DisableLog disables all library log output. Logging output is disabled
// by default until either UseLogger or SetLogWriter are called.
// by default until UseLogger is called.
func DisableLog() {
log = btclog.Disabled
}
Expand All @@ -29,30 +23,6 @@ func DisableLog() {
// using btclog.
func UseLogger(logger btclog.Logger) {
log = logger
btcwallet.UseLogger(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 btclog, UseLogger should
// be used instead.
func SetLogWriter(w io.Writer, level string) error {
if w == nil {
return errors.New("nil writer")
}

lvl, ok := btclog.LogLevelFromString(level)
if !ok {
return errors.New("invalid log level")
}

l, err := btclog.NewLoggerFromWriter(w, lvl)
if err != nil {
return err
}

UseLogger(l)
return nil
}

// logClosure is used to provide a closure over expensive logging operations
Expand Down
18 changes: 10 additions & 8 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import:
version: ^1.2.1
- package: github.com/btcsuite/btclog
- package: github.com/btcsuite/go-flags
- package: github.com/btcsuite/seelog
version: ^2.1.0
- package: github.com/jrick/logrotate
- package: github.com/davecgh/go-spew
subpackages:
- spew
Expand All @@ -14,7 +13,7 @@ import:
- proto
- package: github.com/howeyc/gopass
- package: github.com/roasbeef/btcd
version: 4d38357cee3ed3843cd81a347e1573f037e0301e
version: 34fdda7d41cc47d9456550fd1147a77db89f601a
subpackages:
- blockchain
- btcec
Expand All @@ -24,7 +23,7 @@ import:
- wire
- connmgr
- package: github.com/roasbeef/btcrpcclient
version: 9a7826550df8071460e2f5dd6ed9139dcbf260b8
version: d0f4db8b4dad0ca3d569b804f21247c3dd96acbb
- package: github.com/roasbeef/btcutil
version: a259eaf2ec1b54653cdd67848a41867f280797ee
subpackages:
Expand Down Expand Up @@ -69,4 +68,4 @@ import:
subpackages:
- chaincfg
- package: github.com/lightninglabs/neutrino
version: 38ea335359ce38a83d51caea7a39a3a8658d30a4
version: ccfa94a1c213e5df752c08c7edc30cb0a56d4dcf
32 changes: 2 additions & 30 deletions htlcswitch/log.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package htlcswitch

import (
"errors"
"io"

"github.com/btcsuite/btclog"
)
import "github.com/btcsuite/btclog"

// 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
Expand All @@ -18,7 +13,7 @@ func init() {
}

// DisableLog disables all library log output. Logging output is disabled
// by default until either UseLogger or SetLogWriter are called.
// by default until UseLogger is called.
func DisableLog() {
log = btclog.Disabled
}
Expand All @@ -29,26 +24,3 @@ func DisableLog() {
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 btclog, UseLogger should
// be used instead.
func SetLogWriter(w io.Writer, level string) error {
if w == nil {
return errors.New("nil writer")
}

lvl, ok := btclog.LogLevelFromString(level)
if !ok {
return errors.New("invalid log level")
}

l, err := btclog.NewLoggerFromWriter(w, lvl)
if err != nil {
return err
}

UseLogger(l)
return nil
}
6 changes: 5 additions & 1 deletion lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func lndMain() error {
return err
}
cfg = loadedConfig
defer backendLog.Flush()
defer func() {
if logRotator != nil {
logRotator.Close()
}
}()

// Show version at startup.
ltndLog.Infof("Version %s", version())
Expand Down
28 changes: 1 addition & 27 deletions lnwallet/log.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package lnwallet

import (
"errors"
"io"

"github.com/btcsuite/btclog"
"github.com/roasbeef/btcrpcclient"
"github.com/roasbeef/btcwallet/chain"
Expand All @@ -22,7 +19,7 @@ func init() {
}

// DisableLog disables all library log output. Logging output is disabled
// by default until either UseLogger or SetLogWriter are called.
// by default until UseLogger is called.
func DisableLog() {
walletLog = btclog.Disabled
}
Expand All @@ -39,29 +36,6 @@ func UseLogger(logger btclog.Logger) {
chain.UseLogger(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 btclog, UseLogger should
// be used instead.
func SetLogWriter(w io.Writer, level string) error {
if w == nil {
return errors.New("nil writer")
}

lvl, ok := btclog.LogLevelFromString(level)
if !ok {
return errors.New("invalid log level")
}

l, err := btclog.NewLoggerFromWriter(w, lvl)
if err != nil {
return err
}

UseLogger(l)
return nil
}

// logClosure is used to provide a closure over expensive logging operations
// so don't have to be performed when the logging level doesn't warrant it.
type logClosure func() string
Expand Down
Loading

0 comments on commit 8fa2b95

Please sign in to comment.