• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 12026968820

26 Nov 2024 08:48AM UTC coverage: 49.896% (-9.1%) from 58.999%
12026968820

Pull #9303

github

yyforyongyu
lnwallet: add debug logs
Pull Request #9303: htlcswitch+routing: handle nil pointer dereference properly

20 of 23 new or added lines in 4 files covered. (86.96%)

25375 existing lines in 428 files now uncovered.

99993 of 200404 relevant lines covered (49.9%)

2.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.63
/build/prefix_log.go
1
package build
2

3
import (
4
        "context"
5

6
        btclogv1 "github.com/btcsuite/btclog"
7
        "github.com/btcsuite/btclog/v2"
8
)
9

10
// PrefixLog is a pass-through logger that adds a prefix to every logged line.
11
type PrefixLog struct {
12
        log    btclog.Logger
13
        prefix string
14
        attr   []any
15
}
16

17
// NewPrefixLog instantiates a new prefixed logger.
18
func NewPrefixLog(prefix string, log btclog.Logger, attrs ...any) *PrefixLog {
4✔
19
        return &PrefixLog{
4✔
20
                log:    log,
4✔
21
                prefix: prefix,
4✔
22
                attr:   attrs,
4✔
23
        }
4✔
24
}
4✔
25

26
// addFormatPrefix prepends the prefix to a format string.
27
func (p *PrefixLog) addFormatPrefix(s string) string {
4✔
28
        return p.prefix + " " + s
4✔
29
}
4✔
30

31
// addArgsPrefix prepends the prefix to a list of arguments.
32
func (p *PrefixLog) addArgsPrefix(args []any) []any {
4✔
33
        return append([]interface{}{p.prefix}, args...)
4✔
34
}
4✔
35

36
// mergeAttr merges the given set of attributes with any attributes that the
37
// logger was initialised with.
38
func (p *PrefixLog) mergeAttr(attrs []any) []any {
×
39
        return append(append([]any{}, attrs...), p.attr...)
×
40
}
×
41

42
// Tracef formats message according to format specifier and writes to to log
43
// with LevelTrace.
44
func (p *PrefixLog) Tracef(format string, params ...interface{}) {
4✔
45
        p.log.Tracef(p.addFormatPrefix(format), params...)
4✔
46
}
4✔
47

48
// Debugf formats message according to format specifier and writes to log with
49
// LevelDebug.
50
func (p *PrefixLog) Debugf(format string, params ...interface{}) {
4✔
51
        p.log.Debugf(p.addFormatPrefix(format), params...)
4✔
52
}
4✔
53

54
// Infof formats message according to format specifier and writes to log with
55
// LevelInfo.
56
func (p *PrefixLog) Infof(format string, params ...interface{}) {
4✔
57
        p.log.Infof(p.addFormatPrefix(format), params...)
4✔
58
}
4✔
59

60
// Warnf formats message according to format specifier and writes to to log with
61
// LevelWarn.
62
func (p *PrefixLog) Warnf(format string, params ...interface{}) {
4✔
63
        p.log.Warnf(p.addFormatPrefix(format), params...)
4✔
64
}
4✔
65

66
// Errorf formats message according to format specifier and writes to to log
67
// with LevelError.
68
func (p *PrefixLog) Errorf(format string, params ...interface{}) {
4✔
69
        p.log.Errorf(p.addFormatPrefix(format), params...)
4✔
70
}
4✔
71

72
// Criticalf formats message according to format specifier and writes to log
73
// with LevelCritical.
74
func (p *PrefixLog) Criticalf(format string, params ...interface{}) {
×
75
        p.log.Criticalf(p.addFormatPrefix(format), params...)
×
76
}
×
77

78
// Trace formats message using the default formats for its operands and writes
79
// to log with LevelTrace.
80
func (p *PrefixLog) Trace(v ...interface{}) {
4✔
81
        p.log.Trace(p.addArgsPrefix(v)...)
4✔
82
}
4✔
83

84
// Debug formats message using the default formats for its operands and writes
85
// to log with LevelDebug.
86
func (p *PrefixLog) Debug(v ...interface{}) {
4✔
87
        p.log.Debug(p.addArgsPrefix(v)...)
4✔
88
}
4✔
89

90
// Info formats message using the default formats for its operands and writes to
91
// log with LevelInfo.
92
func (p *PrefixLog) Info(v ...interface{}) {
4✔
93
        p.log.Info(p.addArgsPrefix(v)...)
4✔
94
}
4✔
95

96
// Warn formats message using the default formats for its operands and writes to
97
// log with LevelWarn.
UNCOV
98
func (p *PrefixLog) Warn(v ...interface{}) {
×
UNCOV
99
        p.log.Warn(p.addArgsPrefix(v)...)
×
UNCOV
100
}
×
101

102
// Error formats message using the default formats for its operands and writes
103
// to log with LevelError.
104
func (p *PrefixLog) Error(v ...interface{}) {
4✔
105
        p.log.Error(p.addArgsPrefix(v)...)
4✔
106
}
4✔
107

108
// Critical formats message using the default formats for its operands and
109
// writes to log with LevelCritical.
110
func (p *PrefixLog) Critical(v ...interface{}) {
×
111
        p.log.Critical(p.addArgsPrefix(v)...)
×
112
}
×
113

114
// TraceS writes a structured log with the given message and key-value pair
115
// attributes with LevelTrace to the log.
116
func (p *PrefixLog) TraceS(ctx context.Context, msg string, attrs ...any) {
×
117
        p.log.TraceS(ctx, p.addFormatPrefix(msg), p.mergeAttr(attrs)...)
×
118
}
×
119

120
// DebugS writes a structured log with the given message and key-value pair
121
// attributes with LevelDebug to the log.
122
func (p *PrefixLog) DebugS(ctx context.Context, msg string, attrs ...any) {
×
123
        p.log.DebugS(ctx, p.addFormatPrefix(msg), p.mergeAttr(attrs)...)
×
124
}
×
125

126
// InfoS writes a structured log with the given message and key-value pair
127
// attributes with LevelInfo to the log.
128
func (p *PrefixLog) InfoS(ctx context.Context, msg string, attrs ...any) {
×
129
        p.log.InfoS(ctx, p.addFormatPrefix(msg), p.mergeAttr(attrs)...)
×
130
}
×
131

132
// WarnS writes a structured log with the given message and key-value pair
133
// attributes with LevelWarn to the log.
134
func (p *PrefixLog) WarnS(ctx context.Context, msg string, err error,
135
        attrs ...any) {
×
136

×
137
        p.log.WarnS(ctx, p.addFormatPrefix(msg), err, p.mergeAttr(attrs)...)
×
138
}
×
139

140
// ErrorS writes a structured log with the given message and key-value pair
141
// attributes with LevelError to the log.
142
func (p *PrefixLog) ErrorS(ctx context.Context, msg string, err error,
143
        attrs ...any) {
×
144

×
145
        p.log.ErrorS(ctx, p.addFormatPrefix(msg), err, p.mergeAttr(attrs)...)
×
146
}
×
147

148
// CriticalS writes a structured log with the given message and key-value pair
149
// attributes with LevelCritical to the log.
150
func (p *PrefixLog) CriticalS(ctx context.Context, msg string, err error,
151
        attrs ...any) {
×
152

×
153
        p.log.CriticalS(ctx, p.addFormatPrefix(msg), err, p.mergeAttr(attrs)...)
×
154
}
×
155

156
// Level returns the current logging level.
157
func (p *PrefixLog) Level() btclogv1.Level {
×
158
        return p.log.Level()
×
159
}
×
160

161
// SetLevel changes the logging level to the passed level.
162
func (p *PrefixLog) SetLevel(level btclogv1.Level) {
×
163
        p.log.SetLevel(level)
×
164
}
×
165

166
// Assert that PrefixLog fulfills the btclog.Logger interface.
167
var _ btclog.Logger = &PrefixLog{}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc