log.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package sweep
  2. import (
  3. "github.com/btcsuite/btclog"
  4. "github.com/lightningnetwork/lnd/build"
  5. )
  6. // log is a logger that is initialized with no output filters. This means the
  7. // package will not perform any logging by default until the caller requests
  8. // it.
  9. var log btclog.Logger
  10. // The default amount of logging is none.
  11. func init() {
  12. UseLogger(build.NewSubLogger("SWPR", nil))
  13. }
  14. // DisableLog disables all library log output. Logging output is disabled by
  15. // default until UseLogger is called.
  16. func DisableLog() {
  17. UseLogger(btclog.Disabled)
  18. }
  19. // UseLogger uses a specified Logger to output package logging info. This
  20. // should be used in preference to SetLogWriter if the caller is also using
  21. // btclog.
  22. func UseLogger(logger btclog.Logger) {
  23. log = logger
  24. }
  25. // logClosure is used to provide a closure over expensive logging operations so
  26. // don't have to be performed when the logging level doesn't warrant it.
  27. type logClosure func() string
  28. // String invokes the underlying function and returns the result.
  29. func (c logClosure) String() string {
  30. return c()
  31. }
  32. // newLogClosure returns a new closure over a function that returns a string
  33. // which itself provides a Stringer interface so that it can be used with the
  34. // logging system.
  35. func newLogClosure(c func() string) logClosure {
  36. return logClosure(c)
  37. }