Skip to content

Commit ddf3ed8

Browse files
committed
Fix lint errors
1 parent 43eb704 commit ddf3ed8

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Backend interface {
1313
Log(Level, int, *Record) error
1414
}
1515

16-
// Set backend replaces the backend currently set with the given new logging
16+
// SetBackend replaces the backend currently set with the given new logging
1717
// backend.
1818
func SetBackend(backends ...Backend) LeveledBackend {
1919
var backend Backend

format.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type fmtVerb int
2828
const (
2929
fmtVerbTime fmtVerb = iota
3030
fmtVerbLevel
31-
fmtVerbId
31+
fmtVerbID
3232
fmtVerbPid
3333
fmtVerbProgram
3434
fmtVerbModule
@@ -115,10 +115,10 @@ func getFormatter() Formatter {
115115

116116
var (
117117
// DefaultFormatter is the default formatter used and is only the message.
118-
DefaultFormatter Formatter = MustStringFormatter("%{message}")
118+
DefaultFormatter = MustStringFormatter("%{message}")
119119

120-
// Glog format
121-
GlogFormatter Formatter = MustStringFormatter("%{level:.1s}%{time:0102 15:04:05.999999} %{pid} %{shortfile}] %{message}")
120+
// GlogFormatter mimics the glog format
121+
GlogFormatter = MustStringFormatter("%{level:.1s}%{time:0102 15:04:05.999999} %{pid} %{shortfile}] %{message}")
122122
)
123123

124124
// SetFormatter sets the default formatter for all new backends. A backend will
@@ -131,7 +131,7 @@ func SetFormatter(f Formatter) {
131131
formatter.def = f
132132
}
133133

134-
var formatRe *regexp.Regexp = regexp.MustCompile(`%{([a-z]+)(?::(.*?[^\\]))?}`)
134+
var formatRe = regexp.MustCompile(`%{([a-z]+)(?::(.*?[^\\]))?}`)
135135

136136
type part struct {
137137
verb fmtVerb
@@ -184,7 +184,7 @@ type stringFormatter struct {
184184
// %{shortpkg} Base package path, eg. go-logging
185185
// %{longfunc} Full function name, eg. littleEndian.PutUint32
186186
// %{shortfunc} Base function name, eg. PutUint32
187-
func NewStringFormatter(format string) (*stringFormatter, error) {
187+
func NewStringFormatter(format string) (Formatter, error) {
188188
var fmter = &stringFormatter{}
189189

190190
// Find the boundaries of all %{vars}
@@ -246,7 +246,7 @@ func NewStringFormatter(format string) (*stringFormatter, error) {
246246

247247
// MustStringFormatter is equivalent to NewStringFormatter with a call to panic
248248
// on error.
249-
func MustStringFormatter(format string) *stringFormatter {
249+
func MustStringFormatter(format string) Formatter {
250250
f, err := NewStringFormatter(format)
251251
if err != nil {
252252
panic("Failed to initialized string formatter: " + err.Error())
@@ -272,7 +272,7 @@ func (f *stringFormatter) Format(calldepth int, r *Record, output io.Writer) err
272272
case fmtVerbLevel:
273273
v = r.Level
274274
break
275-
case fmtVerbId:
275+
case fmtVerbID:
276276
v = r.Id
277277
break
278278
case fmtVerbPid:
@@ -349,7 +349,7 @@ type backendFormatter struct {
349349

350350
// NewBackendFormatter creates a new backend which makes all records that
351351
// passes through it beeing formatted by the specific formatter.
352-
func NewBackendFormatter(b Backend, f Formatter) *backendFormatter {
352+
func NewBackendFormatter(b Backend, f Formatter) Backend {
353353
return &backendFormatter{b, f}
354354
}
355355

level.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010
"sync"
1111
)
1212

13+
// ErrInvalidLogLevel is used when an invalid log level has been used.
1314
var ErrInvalidLogLevel = errors.New("logger: invalid log level")
1415

1516
// Level defines all available log levels for log messages.
1617
type Level int
1718

19+
// Log levels.
1820
const (
1921
CRITICAL Level = iota
2022
ERROR
@@ -48,6 +50,8 @@ func LogLevel(level string) (Level, error) {
4850
return ERROR, ErrInvalidLogLevel
4951
}
5052

53+
// Leveled interface is the interface required to be able to add leveled
54+
// logging.
5155
type Leveled interface {
5256
GetLevel(string) Level
5357
SetLevel(Level, string)

log_nix.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func NewLogBackend(out io.Writer, prefix string, flag int) *LogBackend {
4141
return &LogBackend{Logger: log.New(out, prefix, flag)}
4242
}
4343

44+
// Log implements the Backend interface.
4445
func (b *LogBackend) Log(level Level, calldepth int, rec *Record) error {
4546
if b.Color {
4647
buf := &bytes.Buffer{}
@@ -50,9 +51,9 @@ func (b *LogBackend) Log(level Level, calldepth int, rec *Record) error {
5051
// For some reason, the Go logger arbitrarily decided "2" was the correct
5152
// call depth...
5253
return b.Logger.Output(calldepth+2, buf.String())
53-
} else {
54-
return b.Logger.Output(calldepth+2, rec.Formatted(calldepth+1))
5554
}
55+
56+
return b.Logger.Output(calldepth+2, rec.Formatted(calldepth+1))
5657
}
5758

5859
func colorSeq(color color) string {

logger.go

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Record struct {
5555
formatted string
5656
}
5757

58+
// Formatted returns the formatted log record string.
5859
func (r *Record) Formatted(calldepth int) string {
5960
if r.formatted == "" {
6061
var buf bytes.Buffer
@@ -64,6 +65,7 @@ func (r *Record) Formatted(calldepth int) string {
6465
return r.formatted
6566
}
6667

68+
// Message returns the log record message.
6769
func (r *Record) Message() string {
6870
if r.message == nil {
6971
// Redact the arguments that implements the Redactor interface
@@ -78,6 +80,8 @@ func (r *Record) Message() string {
7880
return *r.message
7981
}
8082

83+
// Logger is the actual logger which creates log records based on the functions
84+
// called and passes them to the underlying logging backend.
8185
type Logger struct {
8286
Module string
8387
backend LeveledBackend
@@ -88,12 +92,14 @@ type Logger struct {
8892
ExtraCalldepth int
8993
}
9094

95+
// SetBackend overrides any previously defined backend for this logger.
9196
func (l *Logger) SetBackend(backend LeveledBackend) {
9297
l.backend = backend
9398
l.haveBackend = true
9499
}
95100

96101
// TODO call NewLogger and remove MustGetLogger?
102+
97103
// GetLogger creates and returns a Logger object based on the module name.
98104
func GetLogger(module string) (*Logger, error) {
99105
return &Logger{Module: module}, nil

memory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (b *ChannelMemoryBackend) insertRecord(rec *Record) {
199199
if b.maxSize > 0 && b.size >= b.maxSize {
200200
b.head = b.head.next
201201
} else {
202-
b.size += 1
202+
b.size++
203203
}
204204
}
205205

syslog.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NewSyslogBackendPriority(prefix string, priority syslog.Priority) (b *Syslo
3131
return &SyslogBackend{w}, err
3232
}
3333

34+
// Log implements the Backend interface.
3435
func (b *SyslogBackend) Log(level Level, calldepth int, rec *Record) error {
3536
line := rec.Formatted(calldepth + 1)
3637
switch level {

0 commit comments

Comments
 (0)