github.com/palcoin-project/palcd@v1.0.0/rpcclient/log.go (about) 1 // Copyright (c) 2014-2017 The btcsuite developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package rpcclient 6 7 import "github.com/palcoin-project/palclog" 8 9 // log is a logger that is initialized with no output filters. This 10 // means the package will not perform any logging by default until the caller 11 // requests it. 12 var log palclog.Logger 13 14 // The default amount of logging is none. 15 func init() { 16 DisableLog() 17 } 18 19 // DisableLog disables all library log output. Logging output is disabled 20 // by default until UseLogger is called. 21 func DisableLog() { 22 log = palclog.Disabled 23 } 24 25 // UseLogger uses a specified Logger to output package logging info. 26 func UseLogger(logger palclog.Logger) { 27 log = logger 28 } 29 30 // LogClosure is a closure that can be printed with %v to be used to 31 // generate expensive-to-create data for a detailed log level and avoid doing 32 // the work if the data isn't printed. 33 type logClosure func() string 34 35 // String invokes the log closure and returns the results string. 36 func (c logClosure) String() string { 37 return c() 38 } 39 40 // newLogClosure returns a new closure over the passed function which allows 41 // it to be used as a parameter in a logging function that is only invoked when 42 // the logging level is such that the message will actually be logged. 43 func newLogClosure(c func() string) logClosure { 44 return logClosure(c) 45 }