Skip to content

Commit 6cce8fd

Browse files
bfirshmarkphelpsask-bonk[bot]anish-sahoo
authored
feat: use human-readable log format for local CLI commands (#2806)
* feat: use human-readable log format for local CLI commands Coglet defaults to JSON structured logs for production (GKE/Stackdriver compatibility), but this makes local development output hard to read. Set LOG_FORMAT=console in cog serve, cog run, cog predict, and cog train so developers see human-readable logs locally. Production is unaffected since the env var is only set by the CLI for local commands. * Update pkg/predict/predictor.go Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com> Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com> * chore: appease the linter Signed-off-by: Mark Phelps <mphelps@cloudflare.com> --------- Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com> Signed-off-by: Mark Phelps <mphelps@cloudflare.com> Co-authored-by: Mark Phelps <209477+markphelps@users.noreply.github.com> Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com> Co-authored-by: Mark Phelps <mphelps@cloudflare.com> Co-authored-by: asahoo <anishsahoo2005@gmail.com>
1 parent e6dcdfc commit 6cce8fd

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

pkg/cli/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ func execCmd(cmd *cobra.Command, args []string) error {
9999
gpus = "all"
100100
}
101101

102+
// Use human-readable log format for local development
103+
env := make([]string, len(envFlags))
104+
copy(env, envFlags)
105+
env = append(env, "LOG_FORMAT=console")
106+
102107
// Automatically propagate RUST_LOG for Rust coglet debugging
103-
env := envFlags
104108
if rustLog := os.Getenv("RUST_LOG"); rustLog != "" {
105109
env = append(env, "RUST_LOG="+rustLog)
106110
}

pkg/cli/serve.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ func cmdServe(cmd *cobra.Command, arg []string) error {
115115
args = append(args, "--upload-url", uploadURL)
116116
}
117117

118+
// Use human-readable log format for local development
119+
env := make([]string, len(envFlags))
120+
copy(env, envFlags)
121+
env = append(env, "LOG_FORMAT=console")
122+
118123
// Automatically propagate RUST_LOG for Rust coglet debugging
119-
env := envFlags
120124
if rustLog := os.Getenv("RUST_LOG"); rustLog != "" {
121125
env = append(env, "RUST_LOG="+rustLog)
122126
}

pkg/predict/predictor.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,19 @@ type Predictor struct {
8282
// NewPredictor constructs a Predictor. See PredictorOptions for the
8383
// meaning of each field.
8484
func NewPredictor(_ context.Context, opts PredictorOptions) (*Predictor, error) {
85+
// Use human-readable log format for local development
86+
env := make([]string, len(opts.RunOptions.Env))
87+
copy(env, opts.RunOptions.Env)
88+
env = append(env, "LOG_FORMAT=console")
89+
8590
if global.Debug {
86-
opts.RunOptions.Env = append(opts.RunOptions.Env, "COG_LOG_LEVEL=debug")
91+
env = append(env, "COG_LOG_LEVEL=debug")
8792
} else {
88-
opts.RunOptions.Env = append(opts.RunOptions.Env, "COG_LOG_LEVEL=warning")
93+
env = append(env, "COG_LOG_LEVEL=warning")
8994
}
9095

96+
opts.RunOptions.Env = env
97+
9198
return &Predictor{
9299
runOptions: opts.RunOptions,
93100
isTrain: opts.IsTrain,

0 commit comments

Comments
 (0)