Skip to content

Commit

Permalink
chore: include logpath in case of logflush failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ALX99 committed May 19, 2024
1 parent b8a2482 commit 60f23fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 2 additions & 7 deletions cmd/sail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ func main() {

flush := util.SetupLogger(!isDev)
defer func() {
if err = flush(); err != nil {
fmt.Fprintln(os.Stderr, "failed to flush log: "+err.Error())
if logPath, err := flush(); err != nil {
fmt.Fprintf(os.Stderr, "Failed flushing logs to %q: %v\n", logPath, err)
}
}()
log.Info().Msg("Sail started")

util.SetupStyles()

// m, err := primary.New(state.NewState(), primary.Config{PWDFile: *pwdFile}, cfg)
// if err != nil {
// log.Fatal().Err(err).Send()
// }

cwd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
6 changes: 3 additions & 3 deletions internal/util/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import (
)

// SetupLogger sets up the global logger
func SetupLogger(buffered bool) (flush func() error) {
func SetupLogger(buffered bool) (flush func() (string, error)) {
fPath := path.Join(os.TempDir(), "sail.log")
f, err := os.Create(fPath)
if err != nil {
panic(err)
}

var w io.Writer = f
flush = func() error { return nil }
flush = func() (string, error) { return fPath, nil }

if buffered {
w = bufio.NewWriter(f)
flush = w.(*bufio.Writer).Flush
flush = func() (string, error) { return fPath, w.(*bufio.Writer).Flush() }
}

log.Logger = log.Output(zerolog.ConsoleWriter{
Expand Down

0 comments on commit 60f23fb

Please sign in to comment.