Skip to content

Commit e5d609d

Browse files
authored
Merge pull request #31 from abicky/make-utern-print-logs-as-many-as-possible
Make utern print logs as many as possible
2 parents 4064a64 + 812ef09 commit e5d609d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cloudwatch/cloudwatch.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,26 @@ func (cwl *Client) Tail(ctx context.Context) error {
153153

154154
func (cwl *Client) tail(ctx context.Context, logGroupName string,
155155
start chan struct{}, ch chan *logEvent, errch chan error) error {
156-
lastSeenTime := aws.Int64(cwl.config.StartTime.UTC().Unix() * 1000)
156+
lastEventTime := aws.Int64(cwl.config.StartTime.UTC().Unix() * 1000)
157157

158158
fn := func(res *cloudwatchlogs.FilterLogEventsOutput, lastPage bool) bool {
159159
for _, event := range res.Events {
160160
if cache.Cache.Load(logGroupName, event.EventId) {
161161
continue
162162
}
163-
cache.Cache.Store(logGroupName, event.EventId, event.IngestionTime)
163+
cache.Cache.Store(logGroupName, event.EventId, event.Timestamp)
164164
ch <- &logEvent{
165165
logGroupName: logGroupName,
166166
event: event,
167167
}
168+
169+
if *event.Timestamp > *lastEventTime {
170+
lastEventTime = event.Timestamp
171+
}
168172
}
169173

170-
if lastPage && len(res.Events) > 0 {
171-
lastSeenTime = res.Events[len(res.Events)-1].IngestionTime
172-
cache.Cache.Expire(logGroupName, lastSeenTime)
174+
if lastPage {
175+
cache.Cache.Expire(logGroupName, lastEventTime)
173176
}
174177

175178
return true
@@ -182,7 +185,7 @@ func (cwl *Client) tail(ctx context.Context, logGroupName string,
182185
case <-start:
183186
}
184187

185-
streams, err := cwl.ListStreams(ctx, logGroupName, *lastSeenTime)
188+
streams, err := cwl.ListStreams(ctx, logGroupName, *lastEventTime)
186189
if err != nil {
187190
return err
188191
}
@@ -205,7 +208,7 @@ func (cwl *Client) tail(ctx context.Context, logGroupName string,
205208
LogGroupName: aws.String(logGroupName),
206209
LogStreamNames: streamNames,
207210
Interleaved: aws.Bool(true),
208-
StartTime: lastSeenTime,
211+
StartTime: lastEventTime,
209212
}
210213
if cwl.config.FilterPattern != "" {
211214
input.FilterPattern = aws.String(cwl.config.FilterPattern)

0 commit comments

Comments
 (0)