Skip to content

Commit

Permalink
check interceptlogger statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Bailey committed Apr 1, 2021
1 parent a2184e5 commit 104da44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions hclogvet/example/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

func badHCLog() {
l := hclog.L()
il := hclog.NewInterceptLogger(&hclog.LoggerOptions{})

var (
err = io.EOF
Expand All @@ -21,9 +22,18 @@ func badHCLog() {
l.Error("error opening file", "error", err)
l.Debug("too many connections", "connections", numConnections, "ip", ipAddr)

il.Info("ok", "key", "val")
il.Error("raft request failed", "error", err)
il.Error("error opening file", "error", err)
il.Debug("too many connections", "connections", numConnections, "ip", ipAddr)

// bad
l.Info("bad", "key")
l.Error("raft request failed: %v", err)
l.Error("error opening file", err)
l.Debug("too many connections", numConnections, "ip", ipAddr)
il.Info("bad", "key")
il.Error("raft request failed: %v", err)
il.Error("error opening file", err)
il.Debug("too many connections", numConnections, "ip", ipAddr)
}
3 changes: 2 additions & 1 deletion hclogvet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func run(pass *analysis.Pass) (interface{}, error) {
return true
}

if !isNamedType(recv.Type, "github.com/hashicorp/go-hclog", "Logger") {
if !isNamedType(recv.Type, "github.com/hashicorp/go-hclog", "Logger") &&
!isNamedType(recv.Type, "github.com/hashicorp/go-hclog", "InterceptLogger") {
return true
}

Expand Down

0 comments on commit 104da44

Please sign in to comment.