mirror of https://github.com/lightninglabs/loop
commit
9e5c66c051
@ -1,24 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightninglabs/loop"
|
||||
"github.com/lightninglabs/loop/lndclient"
|
||||
"github.com/lightninglabs/loop/loopdb"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
// 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 (
|
||||
backendLog = btclog.NewBackend(logWriter{})
|
||||
logger = backendLog.Logger("LOOPD")
|
||||
logWriter = build.NewRotatingLogWriter()
|
||||
|
||||
log = build.NewSubLogger("LOOPD", logWriter.GenSubLogger)
|
||||
)
|
||||
|
||||
// logWriter implements an io.Writer that outputs to both standard output and
|
||||
// the write-end pipe of an initialized log rotator.
|
||||
type logWriter struct{}
|
||||
func init() {
|
||||
setSubLogger("LOOPD", log, nil)
|
||||
addSubLogger("LOOP", loop.UseLogger)
|
||||
addSubLogger("LNDC", lndclient.UseLogger)
|
||||
addSubLogger("STORE", loopdb.UseLogger)
|
||||
}
|
||||
|
||||
// addSubLogger is a helper method to conveniently create and register the
|
||||
// logger of a sub system.
|
||||
func addSubLogger(subsystem string, useLogger func(btclog.Logger)) {
|
||||
logger := build.NewSubLogger(subsystem, logWriter.GenSubLogger)
|
||||
setSubLogger(subsystem, logger, useLogger)
|
||||
}
|
||||
|
||||
// setSubLogger is a helper method to conveniently register the logger of a sub
|
||||
// system.
|
||||
func setSubLogger(subsystem string, logger btclog.Logger,
|
||||
useLogger func(btclog.Logger)) {
|
||||
|
||||
func (logWriter) Write(p []byte) (n int, err error) {
|
||||
os.Stdout.Write(p)
|
||||
return len(p), nil
|
||||
logWriter.RegisterSubLogger(subsystem, logger)
|
||||
if useLogger != nil {
|
||||
useLogger(logger)
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,23 @@
|
||||
package lndclient
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
// 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 (
|
||||
backendLog = btclog.NewBackend(logWriter{})
|
||||
logger = backendLog.Logger("LNDCLIENT")
|
||||
)
|
||||
// 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 btclog.Logger
|
||||
|
||||
// logWriter implements an io.Writer that outputs to both standard output and
|
||||
// the write-end pipe of an initialized log rotator.
|
||||
type logWriter struct{}
|
||||
// The default amount of logging is none.
|
||||
func init() {
|
||||
UseLogger(build.NewSubLogger("LNDC", nil))
|
||||
}
|
||||
|
||||
func (logWriter) Write(p []byte) (n int, err error) {
|
||||
os.Stdout.Write(p)
|
||||
return len(p), nil
|
||||
// UseLogger uses a specified Logger to output package logging info.
|
||||
// This should be used in preference to SetLogWriter if the caller is also
|
||||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
||||
|
@ -1,24 +1,23 @@
|
||||
package loop
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
// 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 (
|
||||
backendLog = btclog.NewBackend(logWriter{})
|
||||
logger = backendLog.Logger("CLIENT")
|
||||
)
|
||||
// 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 btclog.Logger
|
||||
|
||||
// logWriter implements an io.Writer that outputs to both standard output and
|
||||
// the write-end pipe of an initialized log rotator.
|
||||
type logWriter struct{}
|
||||
// The default amount of logging is none.
|
||||
func init() {
|
||||
UseLogger(build.NewSubLogger("LOOP", nil))
|
||||
}
|
||||
|
||||
func (logWriter) Write(p []byte) (n int, err error) {
|
||||
os.Stdout.Write(p)
|
||||
return len(p), nil
|
||||
// UseLogger uses a specified Logger to output package logging info.
|
||||
// This should be used in preference to SetLogWriter if the caller is also
|
||||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
||||
|
@ -1,21 +1,23 @@
|
||||
package loopdb
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
var (
|
||||
backendLog = btclog.NewBackend(logWriter{})
|
||||
log = backendLog.Logger("STORE")
|
||||
)
|
||||
// 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 btclog.Logger
|
||||
|
||||
// logWriter implements an io.Writer that outputs to both standard output and
|
||||
// the write-end pipe of an initialized log rotator.
|
||||
type logWriter struct{}
|
||||
// The default amount of logging is none.
|
||||
func init() {
|
||||
UseLogger(build.NewSubLogger("STORE", nil))
|
||||
}
|
||||
|
||||
func (logWriter) Write(p []byte) (n int, err error) {
|
||||
os.Stdout.Write(p)
|
||||
return len(p), nil
|
||||
// UseLogger uses a specified Logger to output package logging info.
|
||||
// This should be used in preference to SetLogWriter if the caller is also
|
||||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
||||
|
Loading…
Reference in New Issue