Skip to content

Commit

Permalink
include full timestamps in the logs (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Zakharov authored Jun 3, 2021
1 parent fcf1c9c commit 110331d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/gatherers/clusterconfig/gather_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type logMessagesFilter struct {
// - containerNameRegexFilter to filter containers in the pod (keep empty to not filter)
// - logMessagesFilter allows you to specify
// - messagesToSearch to filter the logs by substrings (case-insensitive)
// or regex (add `(?i)` in the beginning to make search case-insensitive)
// or regex (add `(?i)` in the beginning to make search case-insensitive). Leave nil to not filter.
// - regexSearch which makes messagesToSearch regex patterns, so you can accomplish more complicated search
// - sinceSeconds which sets the moment to fetch the logs from (current time - sinceSeconds)
// - limitBytes which sets the maximum amount of logs that can be fetched
Expand Down Expand Up @@ -85,6 +85,7 @@ func gatherLogsFromContainers(
Container: container,
SinceSeconds: &messagesFilter.sinceSeconds,
LimitBytes: &messagesFilter.limitBytes,
Timestamps: true,
})

logs, err := filterLogs(ctx, request, messagesFilter.messagesToSearch, messagesFilter.isRegexSearch)
Expand Down Expand Up @@ -129,6 +130,10 @@ func filterLogs(

for scanner.Scan() {
line := scanner.Text()
if messagesToSearch == nil {
result += line + "\n"
}

for _, messageToSearch := range messagesToSearch {
if regexSearch {
matches, err := regexp.MatchString(messageToSearch, line)
Expand Down
1 change: 1 addition & 0 deletions pkg/gatherers/clusterconfig/operators_pods_and_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func fetchPodContainerLog(ctx context.Context,
Container: containerName,
TailLines: tailLines,
LimitBytes: limitBytes,
Timestamps: true,
})
readCloser, err := req.Stream(ctx)
if err != nil {
Expand Down

0 comments on commit 110331d

Please sign in to comment.