Move internal/log from apex/log to log/slog (closes #77)
check / check (push) Failing after 2s
check / check (push) Failing after 2s
internal/log now logs through log/slog. After Init, records go to a small slog.Handler that prints the same lines as before; before Init they go to slog.Default(). The helpers and their call sites are unchanged. With NO_COLOR set on a terminal, log lines are no longer colored. pterm is dropped: it only printed progress lines, which fmt now writes directly, outside slog. apex/log, pterm and their indirect dependencies leave go.mod; golang.org/x/term becomes direct. simplelog is not imported: importing it replaces slog's default handler in every program that imports package mfer. The logger stays process-global, since injecting it would change package mfer's API. Progress and log lines now share the logger's lock, so the check progress test runs check ten times to catch a missing wait. Model: opus-5-5
This commit was merged in pull request #141.
This commit is contained in:
+30
-23
@@ -416,6 +416,11 @@ func (w sharedWriter) Write(p []byte) (int, error) {
|
||||
// its last progress line and clears it before it logs the summary. Progress
|
||||
// writes are slowed down, so a progress goroutine that check did not wait for
|
||||
// would write after the summary, or after the run has returned.
|
||||
//
|
||||
// Progress lines and log lines take the logger's lock, and when the progress
|
||||
// goroutine gets it first the clear lands before the summary even without the
|
||||
// wait. Which goroutine gets it first changes from run to run, so check runs
|
||||
// ten times.
|
||||
func TestCheckClearsProgressBeforeSummary(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -426,33 +431,35 @@ func TestCheckClearsProgressBeforeSummary(t *testing.T) {
|
||||
opts := testOpts([]string{testApp, cmdGenerate, "-q", "-o", testMF, testDir}, fs)
|
||||
require.Equal(t, 0, runCLI(opts), "generate failed: %s", testStderr(t, opts))
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
output bytes.Buffer
|
||||
)
|
||||
for range 10 {
|
||||
var (
|
||||
mu sync.Mutex
|
||||
output bytes.Buffer
|
||||
)
|
||||
|
||||
opts = testOpts([]string{
|
||||
testApp, cmdCheck, "--progress", testFlagBase, testDir, testMF,
|
||||
}, fs)
|
||||
opts.Stdout = sharedWriter{mu: &mu, buf: &output, delay: 100 * time.Millisecond}
|
||||
opts.Stderr = sharedWriter{mu: &mu, buf: &output}
|
||||
require.Equal(t, 0, runCLI(opts))
|
||||
opts = testOpts([]string{
|
||||
testApp, cmdCheck, "--progress", testFlagBase, testDir, testMF,
|
||||
}, fs)
|
||||
opts.Stdout = sharedWriter{mu: &mu, buf: &output, delay: 100 * time.Millisecond}
|
||||
opts.Stderr = sharedWriter{mu: &mu, buf: &output}
|
||||
require.Equal(t, 0, runCLI(opts))
|
||||
|
||||
mu.Lock()
|
||||
got := output.String()
|
||||
mu.Unlock()
|
||||
mu.Lock()
|
||||
got := output.String()
|
||||
mu.Unlock()
|
||||
|
||||
lastProgress := strings.Index(got, "Checking: 1/1 files")
|
||||
progressDone := strings.Index(got, "\r\033[K")
|
||||
summary := strings.Index(got, "checked 1 files")
|
||||
lastProgress := strings.Index(got, "Checking: 1/1 files")
|
||||
progressDone := strings.Index(got, "\r\033[K")
|
||||
summary := strings.Index(got, "checked 1 files")
|
||||
|
||||
require.NotEqual(t, -1, lastProgress, "no last progress line in %q", got)
|
||||
require.NotEqual(t, -1, progressDone, "progress line never cleared in %q", got)
|
||||
require.NotEqual(t, -1, summary, "no summary in %q", got)
|
||||
assert.Less(t, lastProgress, progressDone,
|
||||
"progress cleared before its last line in %q", got)
|
||||
assert.Less(t, progressDone, summary,
|
||||
"summary logged before progress was cleared in %q", got)
|
||||
require.NotEqual(t, -1, lastProgress, "no last progress line in %q", got)
|
||||
require.NotEqual(t, -1, progressDone, "progress line never cleared in %q", got)
|
||||
require.NotEqual(t, -1, summary, "no summary in %q", got)
|
||||
require.Less(t, lastProgress, progressDone,
|
||||
"progress cleared before its last line in %q", got)
|
||||
require.Less(t, progressDone, summary,
|
||||
"summary logged before progress was cleared in %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckCommandWithMissingFile(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user