README.md
1# hclogvet
2
3`hclogvet` is a `go vet` tool for checking that the Trace/Debug/Info/Warn/Error
4methods on `hclog.Logger` are used correctly.
5
6## Usage
7
8This may be used in two ways. It may be invoked directly:
9
10 $ hclogvet .
11 /full/path/to/project/log.go:25:8: invalid number of log arguments to Info (1 valid pair only)
12
13Or via `go vet`:
14
15 $ go vet -vettool=$(which hclogvet)
16 # full/module/path
17 ./log.go:25:8: invalid number of log arguments to Info (1 valid pair only)
18
19## Details
20
21These methods expect an odd number of arguments as in:
22
23 logger.Info("valid login", "account", accountID, "ip", addr)
24
25The leading argument is a message string, and then the remainder of the
26arguments are key/value pairs of additional structured data to log to provide
27context.
28
29`hclogvet` will detect unfortunate errors like:
30
31 logger.Error("raft request failed: %v", err)
32 logger.Error("error opening file", err)
33 logger.Debug("too many connections", numConnections, "ip", ipAddr)
34
35So that the author can correct them:
36
37 logger.Error("raft request failed", "error", err)
38 logger.Error("error opening file", "error", err)
39 logger.Debug("too many connections", "connections", numConnections, "ip", ipAddr)
40