Skip to content

Commit 2601bf3

Browse files
committed
Enhance applogs in ondemand mode
Log warning message and capture all the logs defined under the -appLogs argument instead of skipping them
1 parent 25af694 commit 2601bf3

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

internal/agent/ondemand/ondemand.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,22 +386,44 @@ Ignored errors: %v
386386
}
387387

388388
if appLogsContainDollarSign {
389-
// If any of the appLogs contain '$', choose only the matched appName
390-
appLogsMatchingAppName := config.AppLogs{}
389+
// If appName is empty, we cannot match $<appName> patterns
390+
if appName == "" {
391+
logger.Warn().Msgf(`appLogs contain '$<appName>' pattern but appName is not configured. To resolve this, either:
392+
1. Add -a <appName> argument matching the name in your appLog path
393+
2. Remove '$<appName>' from the appLog file path
394+
Falling back to capture all configured appLogs without appName filtering.`)
395+
396+
// Capture all appLogs by stripping the $<appName> suffix
397+
allAppLogs := config.AppLogs{}
398+
for _, configAppLog := range config.GlobalConfig.AppLogs {
399+
logPath := string(configAppLog)
400+
// Remove any $<appName> suffix pattern
401+
if idx := strings.LastIndex(logPath, "$"); idx != -1 {
402+
logPath = logPath[:idx]
403+
}
404+
allAppLogs = append(allAppLogs, config.AppLog(logPath))
405+
}
391406

392-
for _, configAppLog := range config.GlobalConfig.AppLogs {
393-
searchToken := "$" + appName
407+
appLogs = goCapture(endpoint, capture.WrapRun(&capture.AppLog{Paths: allAppLogs, LineLimit: config.GlobalConfig.AppLogLineCount}))
408+
useGlobalConfigAppLogs = true
409+
} else {
410+
// If any of the appLogs contain '$', choose only the matched appName
411+
appLogsMatchingAppName := config.AppLogs{}
394412

395-
beforeSearchToken, found := strings.CutSuffix(string(configAppLog), searchToken)
396-
if found {
397-
appLogsMatchingAppName = append(appLogsMatchingAppName, config.AppLog(beforeSearchToken))
398-
}
413+
for _, configAppLog := range config.GlobalConfig.AppLogs {
414+
searchToken := "$" + appName
399415

400-
}
416+
beforeSearchToken, found := strings.CutSuffix(string(configAppLog), searchToken)
417+
if found {
418+
appLogsMatchingAppName = append(appLogsMatchingAppName, config.AppLog(beforeSearchToken))
419+
}
401420

402-
if len(appLogsMatchingAppName) > 0 {
403-
appLogs = goCapture(endpoint, capture.WrapRun(&capture.AppLog{Paths: appLogsMatchingAppName, LineLimit: config.GlobalConfig.AppLogLineCount}))
404-
useGlobalConfigAppLogs = true
421+
}
422+
423+
if len(appLogsMatchingAppName) > 0 {
424+
appLogs = goCapture(endpoint, capture.WrapRun(&capture.AppLog{Paths: appLogsMatchingAppName, LineLimit: config.GlobalConfig.AppLogLineCount}))
425+
useGlobalConfigAppLogs = true
426+
}
405427
}
406428
} else {
407429
appLogs = goCapture(endpoint, capture.WrapRun(&capture.AppLog{Paths: config.GlobalConfig.AppLogs, LineLimit: config.GlobalConfig.AppLogLineCount}))

0 commit comments

Comments
 (0)