Skip to content

feat: use human-readable log format for local CLI commands#2806

Open
bfirsh wants to merge 3 commits intomainfrom
use-console-log-format-locally
Open

feat: use human-readable log format for local CLI commands#2806
bfirsh wants to merge 3 commits intomainfrom
use-console-log-format-locally

Conversation

@bfirsh
Copy link
Copy Markdown
Member

@bfirsh bfirsh commented Mar 4, 2026

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.

Before:

Screenshot 2026-03-04 at 17 00 50

After:

Screenshot 2026-03-04 at 17 01 14

@bfirsh bfirsh requested a review from a team as a code owner March 4, 2026 23:02
@michaeldwan michaeldwan added this to the 0.18.0 milestone Mar 5, 2026
@ask-bonk
Copy link
Copy Markdown

ask-bonk bot commented Mar 31, 2026

I'm Bonk, and I've done a quick review of your PR.

Summary: This PR adds LOG_FORMAT=console environment variable to local CLI commands (cog run, cog serve, cog predict, cog train) to display human-readable logs during development instead of JSON.

Issue Found:

In pkg/predict/predictor.go, there's a potential mutation bug. The code directly appends to runOptions.Env without making a copy first. If the caller reuses that slice elsewhere, they'll unexpectedly get the LOG_FORMAT=console variable:

// pkg/predict/predictor.go:62-63
runOptions.Env = append(runOptions.Env, "LOG_FORMAT=console")

Unlike run.go and serve.go which correctly copy envFlags first, NewPredictor modifies the passed-in runOptions.Env directly. This could cause issues if the same environment slice is used for multiple operations.

Recommendation: Follow the same pattern as run.go and serve.go - make a copy before appending:

env := make([]string, len(runOptions.Env))
copy(env, runOptions.Env)
runOptions.Env = append(env, "LOG_FORMAT=console")

This is a medium severity issue because it could cause unexpected behavior if the caller relies on the original environment slice not being modified.

The rest of the changes look good and are consistent with the stated goal.

github run

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.
@markphelps markphelps force-pushed the use-console-log-format-locally branch from 17ca26a to 96c3dbc Compare April 8, 2026 20:17
Copy link
Copy Markdown

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Bonk, and I've done a quick review of your PR.

Summary: This PR adds LOG_FORMAT=console environment variable to local CLI commands to display human-readable logs during development instead of JSON.

Issue Found:

In pkg/predict/predictor.go, there's a mutation bug. The code directly appends to runOptions.Env without making a copy first. If the caller reuses that slice elsewhere, they'll unexpectedly get the LOG_FORMAT=console variable.

@ask-bonk
Copy link
Copy Markdown

ask-bonk bot commented Apr 8, 2026

Done! Posted a review comment about the slice mutation issue in pkg/predict/predictor.go:64.

github run

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>
@ask-bonk
Copy link
Copy Markdown

ask-bonk bot commented Apr 8, 2026

LGTM

The slice mutation bug has been fixed. I notice there's a duplicated comment on lines 63-64 of pkg/predict/predictor.go ("Use human-readable log format for local development" appears twice) - that's a minor cleanup item but doesn't affect functionality.

github run

Signed-off-by: Mark Phelps <mphelps@cloudflare.com>
@markphelps markphelps requested a review from michaeldwan April 8, 2026 20:34
@ask-bonk
Copy link
Copy Markdown

ask-bonk bot commented Apr 8, 2026

LGTM

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants