Skip to content

Commit de1ec28

Browse files
authored
Merge pull request #119 from pohly/error-verbosity
docs: clarify Error semantic
2 parents eeeb624 + f8fce6a commit de1ec28

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

logr.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ limitations under the License.
4343
//
4444
// Info() and Error() are very similar, but they are separate methods so that
4545
// LogSink implementations can choose to do things like attach additional
46-
// information (such as stack traces) on calls to Error().
46+
// information (such as stack traces) on calls to Error(). Error() messages are
47+
// always logged, regardless of the current verbosity. If there is no error
48+
// instance available, passing nil is valid.
4749
//
4850
// Verbosity
4951
//
@@ -53,6 +55,7 @@ limitations under the License.
5355
// Log-lines with V-levels that are not enabled (as per the LogSink) will not
5456
// be written. Level V(0) is the default, and logger.V(0).Info() has the same
5557
// meaning as logger.Info(). Negative V-levels have the same meaning as V(0).
58+
// Error messages do not have a verbosity level and are always logged.
5659
//
5760
// Where we might have written:
5861
// if flVerbose >= 2 {
@@ -253,11 +256,13 @@ func (l Logger) Info(msg string, keysAndValues ...interface{}) {
253256
// Error logs an error, with the given message and key/value pairs as context.
254257
// It functions similarly to Info, but may have unique behavior, and should be
255258
// preferred for logging errors (see the package documentations for more
256-
// information).
259+
// information). The log message will always be emitted, regardless of
260+
// verbosity level.
257261
//
258262
// The msg argument should be used to add context to any underlying error,
259263
// while the err argument should be used to attach the actual error that
260-
// triggered this log line, if present.
264+
// triggered this log line, if present. The err parameter is optional
265+
// and nil may be passed instead of an error instance.
261266
func (l Logger) Error(err error, msg string, keysAndValues ...interface{}) {
262267
if withHelper, ok := l.sink.(CallStackHelperLogSink); ok {
263268
withHelper.GetCallStackHelper()()

0 commit comments

Comments
 (0)