Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve skywire-cli log command #1648

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions cmd/skywire-cli/commands/log/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,31 @@ var logCmd = &cobra.Command{
log.Fatal("use of mutually exclusive flags --log and --survey")
}

ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()
go func() {
<-ctx.Done()
cancel()
os.Exit(1)
}()

// Preparing directories
if _, err := os.ReadDir("log_collecting"); err != nil {
if err := os.Mkdir("log_collecting", 0750); err != nil {
log.Panic("Unable to log_collecting directory")
log.Error("Unable to log_collecting directory")
return
}
}

if err := os.Chdir("log_collecting"); err != nil {
log.Panic("Unable to change directory to log_collecting")
log.Error("Unable to change directory to log_collecting")
return
}

// Create dmsgget instance
dg := dmsgget.New(flag.CommandLine)
flag.Parse()

ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()
go func() {
<-ctx.Done()
cancel()
os.Exit(1)
}()
// Set the uptime tracker to fetch data from
endpoint := skyenv.UptimeTrackerAddr + "/uptimes?v=v2"
if env == "test" {
Expand All @@ -105,7 +108,8 @@ var logCmd = &cobra.Command{
//Fetch the uptime data over http
uptimes, err := getUptimes(endpoint, log)
if err != nil {
log.WithError(err).Panic("Unable to get data from uptime tracker.")
log.WithError(err).Error("Unable to get data from uptime tracker.")
return
}
//randomize the order of the survey collection - workaround for hanging
rand.Shuffle(len(uptimes), func(i, j int) {
Expand All @@ -119,7 +123,8 @@ var logCmd = &cobra.Command{

dmsgC, closeDmsg, err := dg.StartDmsg(ctx, log, pk, sk)
if err != nil {
log.WithError(err).Panic(err)
log.Error(err)
return
}
defer closeDmsg()

Expand Down Expand Up @@ -156,7 +161,8 @@ var logCmd = &cobra.Command{
deleteOnError := false
if _, err := os.ReadDir(key); err != nil {
if err := os.Mkdir(key, 0750); err != nil {
log.Panicf("Unable to create directory for visor %s", key)
log.Errorf("Unable to create directory for visor %s", key)
return
}
deleteOnError = true
}
Expand Down