Skip to content

Commit de31cc7

Browse files
committed
fix: improve logging
1 parent d2c7cf5 commit de31cc7

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

pkg/devspace/devpod/devpod.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (d *devPod) startWithRetry(ctx *devspacecontext.Context, devPodConfig *late
128128

129129
if ctx.IsDone() {
130130
<-t.Dead()
131+
ctx.Log.Debugf("Stopped dev %s", devPodConfig.Name)
131132
close(d.done)
132133
return
133134
}
@@ -145,6 +146,7 @@ func (d *devPod) startWithRetry(ctx *devspacecontext.Context, devPodConfig *late
145146
pod, err := ctx.KubeClient.KubeClient().CoreV1().Pods(selectedPod.Pod.Namespace).Get(ctx.Context, selectedPod.Pod.Name, metav1.GetOptions{})
146147
if err != nil {
147148
if kerrors.IsNotFound(err) {
149+
ctx.Log.Debugf("Restart dev %s because pod isn't found anymore", devPodConfig.Name)
148150
d.restart(ctx, devPodConfig, options)
149151
return true, nil
150152
}
@@ -153,6 +155,7 @@ func (d *devPod) startWithRetry(ctx *devspacecontext.Context, devPodConfig *late
153155
ctx.Log.Debugf("error trying to retrieve pod: %v", err)
154156
return false, nil
155157
} else if pod.DeletionTimestamp != nil {
158+
ctx.Log.Debugf("Restart dev %s because pod is terminating", devPodConfig.Name)
156159
d.restart(ctx, devPodConfig, options)
157160
return true, nil
158161
}
@@ -168,6 +171,7 @@ func (d *devPod) startWithRetry(ctx *devspacecontext.Context, devPodConfig *late
168171
}
169172
}
170173

174+
ctx.Log.Debugf("Stopped dev %s", devPodConfig.Name)
171175
d.m.Lock()
172176
d.err = t.Err()
173177
d.m.Unlock()
@@ -272,6 +276,7 @@ func (d *devPod) start(ctx *devspacecontext.Context, devPodConfig *latest.DevPod
272276
time.Sleep(time.Second * 1)
273277
_ = open.Start(url)
274278
ctx.Log.Donef("Successfully opened %s", url)
279+
return nil
275280
}
276281
}
277282
}

pkg/devspace/services/attach/attach.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func StartAttach(
7373
return
7474
}
7575

76-
ctx.Log.WriteString(logrus.InfoLevel, "\n")
7776
ctx.Log.Infof("Restarting because: %s", err)
7877
select {
7978
case <-ctx.Context.Done():
@@ -83,6 +82,8 @@ func StartAttach(
8382
err = StartAttach(ctx, devContainer, selector, stdout, stderr, stdin, parent)
8483
return
8584
}
85+
86+
ctx.Log.Debugf("Stopped attach")
8687
}()
8788

8889
before := log.GetBaseInstance().GetLevel()

pkg/devspace/services/logs/logs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/loft-sh/devspace/pkg/util/scanner"
99
"github.com/mgutz/ansi"
1010
"github.com/pkg/errors"
11-
"github.com/sirupsen/logrus"
1211
"io"
1312
"time"
1413
)
@@ -40,16 +39,20 @@ func StartLogs(
4039
defer func() {
4140
if err != nil {
4241
if ctx.IsDone() {
43-
err = nil
4442
return
4543
}
4644

47-
ctx.Log.WriteString(logrus.InfoLevel, "\n")
4845
ctx.Log.Infof("Restarting because: %s", err)
49-
time.Sleep(time.Second * 3)
46+
select {
47+
case <-ctx.Context.Done():
48+
return
49+
case <-time.After(time.Second * 3):
50+
}
5051
err = StartLogs(ctx, devContainer, selector)
5152
return
5253
}
54+
55+
ctx.Log.Debugf("Stopped logs")
5356
}()
5457

5558
containerObj, err := selector.WithContainer(devContainer.Container).SelectSingleContainer(ctx.Context, ctx.KubeClient, ctx.Log)

pkg/devspace/services/terminal/terminal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func StartTerminal(
104104
return
105105
}
106106

107-
ctx.Log.WriteString(logrus.InfoLevel, "\n")
108107
ctx.Log.Infof("Restarting because: %s", err)
109108
select {
110109
case <-ctx.Context.Done():
@@ -114,6 +113,8 @@ func StartTerminal(
114113
err = StartTerminal(ctx, devContainer, selector, stdout, stderr, stdin, parent)
115114
return
116115
}
116+
117+
ctx.Log.Debugf("Stopped terminal")
117118
}()
118119

119120
command := getCommand(devContainer)

0 commit comments

Comments
 (0)