console-slog icon indicating copy to clipboard operation
console-slog copied to clipboard

Debug logs are treated as errors

Open JDiPierro opened this issue 8 months ago • 1 comments

I copied the exact example from the README:

package main

import (
	"errors"
	"log/slog"
	"os"

	"github.com/phsym/console-slog"
)

func main() {
	logger := slog.New(
		console.NewHandler(os.Stderr, &console.HandlerOptions{Level: slog.LevelDebug}),
	)
	slog.SetDefault(logger)
	slog.Info("Hello world!", "foo", "bar")
	slog.Debug("Debug message")
	slog.Warn("Warning message")
	slog.Error("Error message", "err", errors.New("the error"))

	logger = logger.With("foo", "bar").
		WithGroup("the-group").
		With("bar", "baz")

	logger.Info("group info", "attr", "value")
}

and the Debug level log is output with red text as if it's an error.. it seems like attributes are always considered errors as well:

Image

JDiPierro avatar May 30 '25 14:05 JDiPierro

The issue appears to be with using os.Stderr as the output writer.. Switching that to os.Stdout resolves the improper coloring:

Image

JDiPierro avatar May 30 '25 14:05 JDiPierro