Skip to content

Commit 62ff9ce

Browse files
committed
touch-up some godoc and add "doc" links.
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 567ce85 commit 62ff9ce

File tree

4 files changed

+42
-39
lines changed

4 files changed

+42
-39
lines changed

entry.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func init() {
3434
minimumCallerDepth = 1
3535
}
3636

37-
// Defines the key when adding errors using WithError.
37+
// ErrorKey defines the key when adding errors using [WithError], [Logger.WithError].
3838
var ErrorKey = "error"
3939

40-
// An entry is the final or intermediate Logrus logging entry. It contains all
40+
// Entry is the final or intermediate Logrus logging entry. It contains all
4141
// the fields passed with WithField{,s}. It's finally logged when Trace, Debug,
4242
// Info, Warn, Error, Fatal or Panic is called on it. These objects can be
4343
// reused and passed around as much as you wish to avoid field duplication.
@@ -88,12 +88,12 @@ func (entry *Entry) Dup() *Entry {
8888
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, Context: entry.Context, err: entry.err}
8989
}
9090

91-
// Returns the bytes representation of this entry from the formatter.
91+
// Bytes returns the bytes representation of this entry from the formatter.
9292
func (entry *Entry) Bytes() ([]byte, error) {
9393
return entry.Logger.Formatter.Format(entry)
9494
}
9595

96-
// Returns the string representation from the reader and ultimately the
96+
// String returns the string representation from the reader and ultimately the
9797
// formatter.
9898
func (entry *Entry) String() (string, error) {
9999
serialized, err := entry.Bytes()
@@ -104,12 +104,13 @@ func (entry *Entry) String() (string, error) {
104104
return str, nil
105105
}
106106

107-
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
107+
// WithError adds an error as single field (using the key defined in [ErrorKey])
108+
// to the Entry.
108109
func (entry *Entry) WithError(err error) *Entry {
109110
return entry.WithField(ErrorKey, err)
110111
}
111112

112-
// Add a context to the Entry.
113+
// WithContext adds a context to the Entry.
113114
func (entry *Entry) WithContext(ctx context.Context) *Entry {
114115
dataCopy := make(Fields, len(entry.Data))
115116
for k, v := range entry.Data {
@@ -118,12 +119,12 @@ func (entry *Entry) WithContext(ctx context.Context) *Entry {
118119
return &Entry{Logger: entry.Logger, Data: dataCopy, Time: entry.Time, err: entry.err, Context: ctx}
119120
}
120121

121-
// Add a single field to the Entry.
122+
// WithField adds a single field to the Entry.
122123
func (entry *Entry) WithField(key string, value interface{}) *Entry {
123124
return entry.WithFields(Fields{key: value})
124125
}
125126

126-
// Add a map of fields to the Entry.
127+
// WithFields adds a map of fields to the Entry.
127128
func (entry *Entry) WithFields(fields Fields) *Entry {
128129
data := make(Fields, len(entry.Data)+len(fields))
129130
for k, v := range entry.Data {
@@ -152,7 +153,7 @@ func (entry *Entry) WithFields(fields Fields) *Entry {
152153
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context}
153154
}
154155

155-
// Overrides the time of the Entry.
156+
// WithTime overrides the time of the Entry.
156157
func (entry *Entry) WithTime(t time.Time) *Entry {
157158
dataCopy := make(Fields, len(entry.Data))
158159
for k, v := range entry.Data {
@@ -434,7 +435,7 @@ func (entry *Entry) Panicln(args ...interface{}) {
434435
entry.Logln(PanicLevel, args...)
435436
}
436437

437-
// Sprintlnn => Sprint no newline. This is to get the behavior of how
438+
// sprintlnn => Sprint no newline. This is to get the behavior of how
438439
// fmt.Sprintln where spaces are always added between operands, regardless of
439440
// their type. Instead of vendoring the Sprintln implementation to spare a
440441
// string allocation, we do the simplest thing.

hooks.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package logrus
22

3-
// A hook to be fired when logging on the logging levels returned from
4-
// `Levels()` on your implementation of the interface. Note that this is not
3+
// Hook describes hooks to be fired when logging on the logging levels returned from
4+
// [Hook.Levels] on your implementation of the interface. Note that this is not
55
// fired in a goroutine or a channel with workers, you should handle such
6-
// functionality yourself if your call is non-blocking and you don't wish for
6+
// functionality yourself if your call is non-blocking, and you don't wish for
77
// the logging calls for levels returned from `Levels()` to block.
88
type Hook interface {
99
Levels() []Level
1010
Fire(*Entry) error
1111
}
1212

13-
// Internal type for storing the hooks on a logger instance.
13+
// LevelHooks is an internal type for storing the hooks on a logger instance.
1414
type LevelHooks map[Level][]Hook
1515

1616
// Add a hook to an instance of logger. This is called with

logger.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ func (mw *MutexWrap) Disable() {
7272
mw.disabled = true
7373
}
7474

75-
// Creates a new logger. Configuration should be set by changing `Formatter`,
76-
// `Out` and `Hooks` directly on the default logger instance. You can also just
75+
// New Creates a new logger. Configuration should be set by changing [Formatter],
76+
// Out and Hooks directly on the default Logger instance. You can also just
7777
// instantiate your own:
7878
//
79-
// var log = &logrus.Logger{
80-
// Out: os.Stderr,
81-
// Formatter: new(logrus.TextFormatter),
82-
// Hooks: make(logrus.LevelHooks),
83-
// Level: logrus.DebugLevel,
84-
// }
79+
// var log = &logrus.Logger{
80+
// Out: os.Stderr,
81+
// Formatter: new(logrus.TextFormatter),
82+
// Hooks: make(logrus.LevelHooks),
83+
// Level: logrus.DebugLevel,
84+
// }
8585
//
8686
// It's recommended to make this a global instance called `log`.
8787
func New() *Logger {
@@ -118,30 +118,30 @@ func (logger *Logger) WithField(key string, value interface{}) *Entry {
118118
return entry.WithField(key, value)
119119
}
120120

121-
// Adds a struct of fields to the log entry. All it does is call `WithField` for
122-
// each `Field`.
121+
// WithFields adds a struct of fields to the log entry. It calls [Entry.WithField]
122+
// for each Field.
123123
func (logger *Logger) WithFields(fields Fields) *Entry {
124124
entry := logger.newEntry()
125125
defer logger.releaseEntry(entry)
126126
return entry.WithFields(fields)
127127
}
128128

129-
// Add an error as single field to the log entry. All it does is call
130-
// `WithError` for the given `error`.
129+
// WithError adds an error as single field to the log entry. It calls
130+
// [Entry.WithError] for the given error.
131131
func (logger *Logger) WithError(err error) *Entry {
132132
entry := logger.newEntry()
133133
defer logger.releaseEntry(entry)
134134
return entry.WithError(err)
135135
}
136136

137-
// Add a context to the log entry.
137+
// WithContext add a context to the log entry.
138138
func (logger *Logger) WithContext(ctx context.Context) *Entry {
139139
entry := logger.newEntry()
140140
defer logger.releaseEntry(entry)
141141
return entry.WithContext(ctx)
142142
}
143143

144-
// Overrides the time of the log entry.
144+
// WithTime overrides the time of the log entry.
145145
func (logger *Logger) WithTime(t time.Time) *Entry {
146146
entry := logger.newEntry()
147147
defer logger.releaseEntry(entry)
@@ -347,9 +347,9 @@ func (logger *Logger) Exit(code int) {
347347
logger.ExitFunc(code)
348348
}
349349

350-
//When file is opened with appending mode, it's safe to
351-
//write concurrently to a file (within 4k message on Linux).
352-
//In these cases user can choose to disable the lock.
350+
// SetNoLock disables the lock for situations where a file is opened with
351+
// appending mode, and safe for concurrent writes to the file (within 4k
352+
// message on Linux). In these cases user can choose to disable the lock.
353353
func (logger *Logger) SetNoLock() {
354354
logger.mu.Disable()
355355
}

logrus.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"strings"
77
)
88

9-
// Fields type, used to pass to `WithFields`.
9+
// Fields type, used to pass to [WithFields].
1010
type Fields map[string]interface{}
1111

1212
// Level type
1313
//
1414
//nolint:recvcheck // the methods of "Entry" use pointer receiver and non-pointer receiver.
1515
type Level uint32
1616

17-
// Convert the Level to a string. E.g. PanicLevel becomes "panic".
17+
// Convert the Level to a string. E.g. [PanicLevel] becomes "panic".
1818
func (level Level) String() string {
1919
if b, err := level.MarshalText(); err == nil {
2020
return string(b)
@@ -79,7 +79,7 @@ func (level Level) MarshalText() ([]byte, error) {
7979
return nil, fmt.Errorf("not a valid logrus level %d", level)
8080
}
8181

82-
// A constant exposing all logging levels
82+
// AllLevels exposing all logging levels.
8383
var AllLevels = []Level{
8484
PanicLevel,
8585
FatalLevel,
@@ -121,8 +121,8 @@ var (
121121
)
122122

123123
// StdLogger is what your logrus-enabled library should take, that way
124-
// it'll accept a stdlib logger and a logrus logger. There's no standard
125-
// interface, this is the closest we get, unfortunately.
124+
// it'll accept a stdlib logger ([log.Logger]) and a logrus logger.
125+
// There's no standard interface, so this is the closest we get, unfortunately.
126126
type StdLogger interface {
127127
Print(...interface{})
128128
Printf(string, ...interface{})
@@ -137,7 +137,8 @@ type StdLogger interface {
137137
Panicln(...interface{})
138138
}
139139

140-
// The FieldLogger interface generalizes the Entry and Logger types
140+
// FieldLogger extends the [StdLogger] interface, generalizing
141+
// the [Entry] and [Logger] types.
141142
type FieldLogger interface {
142143
WithField(key string, value interface{}) *Entry
143144
WithFields(fields Fields) *Entry
@@ -178,8 +179,9 @@ type FieldLogger interface {
178179
// IsPanicEnabled() bool
179180
}
180181

181-
// Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is
182-
// here for consistancy. Do not use. Use Logger or Entry instead.
182+
// Ext1FieldLogger (the first extension to [FieldLogger]) is superfluous, it is
183+
// here for consistency. Do not use. Use [FieldLogger], [Logger] or [Entry]
184+
// instead.
183185
type Ext1FieldLogger interface {
184186
FieldLogger
185187
Tracef(format string, args ...interface{})

0 commit comments

Comments
 (0)