Skip to content

Commit 62c00f5

Browse files
committed
Show dump logs location if it is not empty
1 parent adeb5a8 commit 62c00f5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

internal/stack/dump.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ type DumpResult struct {
4646

4747
// Dump function exports stack data and dumps them as local artifacts, which can be used for debug purposes.
4848
func Dump(ctx context.Context, options DumpOptions) ([]DumpResult, error) {
49-
logger.Debugf("Dump Elastic stack data")
49+
targetPathLogMessage := ""
50+
if options.Output != "" {
51+
targetPathLogMessage = fmt.Sprintf(" (location: %s)", options.Output)
52+
}
53+
logger.Debugf("Dump Elastic stack data%s", targetPathLogMessage)
5054

5155
results, err := dumpStackLogs(ctx, options)
5256
if err != nil {
@@ -56,12 +60,6 @@ func Dump(ctx context.Context, options DumpOptions) ([]DumpResult, error) {
5660
}
5761

5862
func dumpStackLogs(ctx context.Context, options DumpOptions) ([]DumpResult, error) {
59-
logger.Debugf("Dump stack logs (location: %s)", options.Output)
60-
err := os.RemoveAll(options.Output)
61-
if err != nil {
62-
return nil, fmt.Errorf("can't remove output location: %w", err)
63-
}
64-
6563
localServices := &localServicesManager{
6664
profile: options.Profile,
6765
}
@@ -78,6 +76,11 @@ func dumpStackLogs(ctx context.Context, options DumpOptions) ([]DumpResult, erro
7876

7977
var logsPath string
8078
if options.Output != "" {
79+
err := os.RemoveAll(options.Output)
80+
if err != nil {
81+
return nil, fmt.Errorf("can't remove output location: %w", err)
82+
}
83+
8184
logsPath = filepath.Join(options.Output, "logs")
8285
err = os.MkdirAll(logsPath, 0755)
8386
if err != nil {
@@ -91,7 +94,6 @@ func dumpStackLogs(ctx context.Context, options DumpOptions) ([]DumpResult, erro
9194
if len(options.Services) > 0 && !slices.Contains(options.Services, serviceName) {
9295
continue
9396
}
94-
9597
logger.Debugf("Dump stack logs for %s", serviceName)
9698

9799
content, err := dockerComposeLogsSince(ctx, serviceName, options.Profile, options.Since)

0 commit comments

Comments
 (0)