Skip to content

Commit

Permalink
Adjust output streams
Browse files Browse the repository at this point in the history
- Changed outputs from Stdout to Stderr for logging and help messages.
- Ensured normal command outputs continue to be directed to Stdout.
- Updated logger to use Stderr for consistency in error and log handling.
  • Loading branch information
matsuu committed Sep 1, 2024
1 parent ea0782e commit 1e374e3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/gsa/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func init() {
NoAppSummary: true,
}),
kong.Help(func(options kong.HelpOptions, ctx *kong.Context) error {
utils.Must2(ctx.Stdout.Write([]byte("Usage: \n\tgsa <file> [flags]\n")))
utils.Must2(ctx.Stdout.Write([]byte("\tgsa <old file> <new file> [flags]\n")))
utils.Must2(ctx.Stderr.Write([]byte("Usage: \n\tgsa <file> [flags]\n")))
utils.Must2(ctx.Stderr.Write([]byte("\tgsa <old file> <new file> [flags]\n")))
return kong.DefaultHelpPrinter(options, ctx)
}),
kong.ExplicitGroups([]kong.Group{
Expand Down
2 changes: 1 addition & 1 deletion cmd/gsa/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func entry() error {
return err
}
} else {
writer = utils.Stdout
writer = os.Stdout
if Options.Web {
writer = new(bytes.Buffer)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/utils/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var startTime time.Time

func InitLogger(level slog.Level) {
startTime = time.Now()
slog.SetDefault(slog.New(slog.NewTextHandler(Stdout, &slog.HandlerOptions{
slog.SetDefault(slog.New(slog.NewTextHandler(Stderr, &slog.HandlerOptions{

Check warning on line 16 in internal/utils/log.go

View check run for this annotation

Codecov / codecov/patch

internal/utils/log.go#L16

Added line #L16 was not covered by tests
ReplaceAttr: func(_ []string, a slog.Attr) slog.Attr {
// remove time
if a.Key == "time" {
Expand Down Expand Up @@ -60,9 +60,9 @@ func (s *SyncOutput) SetOutput(output io.Writer) {
s.output = output
}

var Stdout = &SyncOutput{
var Stderr = &SyncOutput{
Mutex: sync.Mutex{},
output: os.Stderr,
}

var _ io.Writer = Stdout
var _ io.Writer = Stderr
2 changes: 1 addition & 1 deletion internal/webui/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (UpdateCacheFlag) BeforeReset(app *kong.Kong, _ kong.Vars) error {
if err != nil {
return err
}
_, err = fmt.Fprintf(app.Stdout, "Cache updated: %s\n", p)
_, err = fmt.Fprintf(app.Stderr, "Cache updated: %s\n", p)
if err != nil {
return err
}
Expand Down

0 comments on commit 1e374e3

Please sign in to comment.