Created
November 12, 2025 09:54
-
-
Save zhangyoufu/f1ff2681d4d166cf67e8260f63ed8dc8 to your computer and use it in GitHub Desktop.
if stdout is tty: log text to stderr; else: log json to stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "github.com/mattn/go-isatty" | |
| func init() { | |
| if isatty.IsTerminal(os.Stdout.Fd()) { | |
| slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, nil))) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment