mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 18:10:48 +02:00
build+sample_conf: option to print log call-site
This commit is contained in:
@ -17,6 +17,10 @@ const (
|
||||
faintSeq = "2"
|
||||
esc = '\x1b'
|
||||
csi = string(esc) + "["
|
||||
|
||||
callSiteOff = "off"
|
||||
callSiteShort = "short"
|
||||
callSiteLong = "long"
|
||||
)
|
||||
|
||||
// LogConfig holds logging configuration options.
|
||||
@ -27,22 +31,51 @@ type LogConfig struct {
|
||||
File *LoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."`
|
||||
}
|
||||
|
||||
// DefaultLogConfig returns the default logging config options.
|
||||
func DefaultLogConfig() *LogConfig {
|
||||
return &LogConfig{
|
||||
Console: &consoleLoggerCfg{
|
||||
LoggerConfig: LoggerConfig{
|
||||
CallSite: callSiteShort,
|
||||
},
|
||||
},
|
||||
File: &LoggerConfig{
|
||||
CallSite: callSiteOff,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// LoggerConfig holds options for a particular logger.
|
||||
//
|
||||
//nolint:lll
|
||||
type LoggerConfig struct {
|
||||
Disable bool `long:"disable" description:"Disable this logger."`
|
||||
NoTimestamps bool `long:"no-timestamps" description:"Omit timestamps from log lines."`
|
||||
Disable bool `long:"disable" description:"Disable this logger."`
|
||||
NoTimestamps bool `long:"no-timestamps" description:"Omit timestamps from log lines."`
|
||||
CallSite string `long:"call-site" description:"Include the call-site of each log line." choice:"off" choice:"short" choice:"long"`
|
||||
}
|
||||
|
||||
// HandlerOptions returns the set of btclog.HandlerOptions that the state of the
|
||||
// config struct translates to.
|
||||
func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption {
|
||||
var opts []btclog.HandlerOption
|
||||
opts := []btclog.HandlerOption{
|
||||
// The default skip depth used by the logging library is 6 but
|
||||
// since we wrap the logging handlers with another level of
|
||||
// abstraction with the handlerSet, we increase the skip depth
|
||||
// to 7 here.
|
||||
btclog.WithCallSiteSkipDepth(7),
|
||||
}
|
||||
|
||||
if cfg.NoTimestamps {
|
||||
opts = append(opts, btclog.WithNoTimestamp())
|
||||
}
|
||||
|
||||
switch cfg.CallSite {
|
||||
case callSiteShort:
|
||||
opts = append(opts, btclog.WithCallerFlags(btclog.Lshortfile))
|
||||
case callSiteLong:
|
||||
opts = append(opts, btclog.WithCallerFlags(btclog.Llongfile))
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
@ -87,14 +120,6 @@ func (cfg *consoleLoggerCfg) HandlerOptions() []btclog.HandlerOption {
|
||||
)
|
||||
}
|
||||
|
||||
// DefaultLogConfig returns the default logging config options.
|
||||
func DefaultLogConfig() *LogConfig {
|
||||
return &LogConfig{
|
||||
Console: &consoleLoggerCfg{},
|
||||
File: &LoggerConfig{},
|
||||
}
|
||||
}
|
||||
|
||||
func styleString(s string, styles ...string) string {
|
||||
if len(styles) == 0 {
|
||||
return s
|
||||
|
Reference in New Issue
Block a user