Skip to content

Commit 95b7cb9

Browse files
authored
Add lint rule to prevent use of stdlib log package (#4957)
## Summary - Add a `depguard` rule that blocks `import "log"` and points to `libs/log` - Migrate the single existing violation in `libs/appproxy` - Exclude build tools (`docsgen`, `schema`, `validation`) that use `log.Fatal` This pull request was AI-assisted by Isaac.
1 parent 8567847 commit 95b7cb9

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

.golangci.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ linters:
3838
deny:
3939
- pkg: "math/rand$"
4040
desc: "use math/rand/v2 instead of math/rand"
41+
no-stdlib-log:
42+
files:
43+
- "**"
44+
- "!**/bundle/docsgen/**"
45+
- "!**/bundle/internal/schema/**"
46+
- "!**/bundle/internal/validation/**"
47+
deny:
48+
- pkg: "log$"
49+
desc: "use libs/log instead of the standard library log package"
4150
forbidigo:
4251
forbid:
4352
- pattern: 'term\.IsTerminal'

libs/appproxy/appproxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package appproxy
33
import (
44
"context"
55
"io"
6-
"log"
76
"net"
87
"net/http"
98
"net/url"
109
"strings"
10+
11+
"github.com/databricks/cli/libs/log"
1112
)
1213

1314
type Proxy struct {
@@ -122,7 +123,7 @@ func (p *Proxy) handleWebSocket(w http.ResponseWriter, r *http.Request) {
122123
// If the error is not EOF, then there was a problem
123124
if err != io.EOF {
124125
// Log the error and perform cleanup
125-
log.Printf("Error copying messages: %v", err)
126+
log.Warnf(r.Context(), "error copying messages: %v", err)
126127
middlewareConn.Close()
127128
targetServerConn.Close()
128129
}

0 commit comments

Comments
 (0)