Skip to content

Commit 075cab6

Browse files
committed
cmd/go-cache-plugin: make the --debug flag a bit vector
1 parent 7ce0424 commit 075cab6

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

cmd/go-cache-plugin/commands.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ var flags struct {
3333
PrintMetrics bool `flag:"metrics,default=$GOCACHE_METRICS,Print summary metrics to stderr at exit"`
3434
Expiration time.Duration `flag:"expiry,default=$GOCACHE_EXPIRY,Cache expiration period (optional)"`
3535
Verbose bool `flag:"v,default=$GOCACHE_VERBOSE,Enable verbose logging"`
36-
DebugLog bool `flag:"debug,default=$GOCACHE_DEBUG,Enable detailed per-request debug logging (noisy)"`
36+
DebugLog int `flag:"debug,default=$GOCACHE_DEBUG,Enable detailed per-request debug logging (noisy)"`
3737
}
3838

39+
const (
40+
debugBuildCache = 1 << iota
41+
debugModProxy
42+
debugRevProxy
43+
)
44+
3945
// runDirect runs a cache communicating on stdin/stdout, for use as a direct
4046
// GOCACHEPROG plugin.
4147
func runDirect(env *command.Env) error {

cmd/go-cache-plugin/go-cache-plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func getBucketRegion(ctx context.Context, bucket string) (string, error) {
9494
// vprintf acts as log.Printf if the --verbose flag is set; otherwise it
9595
// discards its input.
9696
func vprintf(msg string, args ...any) {
97-
if flags.Verbose {
97+
if flags.Verbose || flags.DebugLog != 0 {
9898
log.Printf(msg, args...)
9999
}
100100
}

cmd/go-cache-plugin/help.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ settings can be set via environment variables as well as flags.
4545
-c GOCACHE_CONCURRENCY int runtime.NumCPU
4646
-u GOCACHE_S3_CONCURRENCY duration runtime.NumCPU
4747
-v GOCACHE_VERBOSE bool false
48-
--debug GOCACHE_DEBUG bool false
48+
--debug GOCACHE_DEBUG int 0 (see "help debug")
4949
5050
--------------------------------------------------------------------
5151
Flag (serve) Variable Format Default
@@ -135,4 +135,17 @@ server generates its own TLS certificate, and tries to install a custom signing
135135
cert so that other tools will validate it. The ability to do this varies by
136136
system and configuration, however.`,
137137
},
138+
{
139+
Name: "debug",
140+
Help: `Enable detailed debug logging.
141+
142+
The --debug flag enables (very) verbose debug logging for the components of the
143+
cache plugin. The value of the flag is a bit mask of:
144+
145+
1: Go build cache
146+
2: Go module proxy and sum database
147+
4: HTTP reverse proxy
148+
149+
The default is 0 (no debug logging).`,
150+
},
138151
}

cmd/go-cache-plugin/setup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func initCacheServer(env *command.Env) (*gocache.Server, *s3util.Client, error)
8585
SetMetrics: cache.SetMetrics,
8686
MaxRequests: flags.Concurrency,
8787
Logf: vprintf,
88-
LogRequests: flags.DebugLog,
88+
LogRequests: flags.DebugLog&debugBuildCache != 0,
8989
}
9090
expvar.Publish("gocache_server", s.Metrics().Get("server"))
9191
return s, client, nil
@@ -111,7 +111,7 @@ func initModProxy(env *command.Env, s3c *s3util.Client) (_ http.Handler, cleanup
111111
KeyPrefix: path.Join(flags.KeyPrefix, "module"),
112112
MaxTasks: flags.S3Concurrency,
113113
Logf: vprintf,
114-
LogRequests: flags.DebugLog,
114+
LogRequests: flags.DebugLog&debugModProxy != 0,
115115
}
116116
cleanup = func() { vprintf("close cacher (err=%v)", cacher.Close()) }
117117
proxy := &goproxy.Goproxy{
@@ -163,7 +163,7 @@ func initRevProxy(env *command.Env, s3c *s3util.Client, g *taskgroup.Group) (htt
163163
S3Client: s3c,
164164
KeyPrefix: path.Join(flags.KeyPrefix, "revproxy"),
165165
Logf: vprintf,
166-
LogRequests: flags.DebugLog,
166+
LogRequests: flags.DebugLog&debugRevProxy != 0,
167167
}
168168
bridge := &proxyconn.Bridge{
169169
Addrs: hosts,

0 commit comments

Comments
 (0)