本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/cloudwatchlogs.CloudWatchLogs.GetLogEvents方法的典型用法代碼示例。如果您正苦於以下問題:Golang CloudWatchLogs.GetLogEvents方法的具體用法?Golang CloudWatchLogs.GetLogEvents怎麽用?Golang CloudWatchLogs.GetLogEvents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aws/aws-sdk-go/service/cloudwatchlogs.CloudWatchLogs
的用法示例。
在下文中一共展示了CloudWatchLogs.GetLogEvents方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: log
// Helper to get all the log messages from a stream. Takes the following args.
// * The CloudWatch Logs connection
// * The name of the Group
// * The name of the stream
// * The unix beginning time
// * The unix finished time
// * The color of the string to be printed
func log(svc *cloudwatchlogs.CloudWatchLogs, g string, s string, b int64, f int64, c string) (Rows, error) {
var rows Rows
params := &cloudwatchlogs.GetLogEventsInput{
LogGroupName: aws.String(g),
LogStreamName: aws.String(s),
StartTime: aws.Int64(b),
EndTime: aws.Int64(f),
}
resp, err := svc.GetLogEvents(params)
if err != nil {
return rows, err
}
for _, e := range resp.Events {
r := Row{
Time: *e.Timestamp,
Color: c,
Message: *e.Message,
}
rows = append(rows, &r)
}
return rows, nil
}
示例2: getLog
func getLog(cw *cloudwatchlogs.CloudWatchLogs, name string) (string, error) {
groupPrefix := aws.String("/aws/lambda/" + name)
groups, err := cw.DescribeLogGroups(&cloudwatchlogs.DescribeLogGroupsInput{LogGroupNamePrefix: groupPrefix})
if err != nil {
return "", err
}
if len(groups.LogGroups) < 1 {
return "", errors.New(fmt.Sprintf("No log group found for %s", name))
}
group := groups.LogGroups[0]
// We don't handle the case where lambda functions may share prefixes but we get the list of groups back in non-lexicographic order. Reminder in case that ever happens.
if *group.LogGroupName != *groupPrefix {
log.Fatal("Got group matching prefix but not actual", groupPrefix, group.LogGroupName)
}
streams, err := cw.DescribeLogStreams(&cloudwatchlogs.DescribeLogStreamsInput{
LogGroupName: group.LogGroupName,
Descending: aws.Bool(true),
OrderBy: aws.String("LastEventTime"),
})
if err != nil {
return "", err
}
if len(streams.LogStreams) < 1 {
return "", errors.New(fmt.Sprintf("No log streams found for %s", name))
}
stream := streams.LogStreams[0]
get_log_input := &cloudwatchlogs.GetLogEventsInput{
LogStreamName: stream.LogStreamName,
LogGroupName: group.LogGroupName,
StartFromHead: aws.Bool(true),
// allow 3 minute local vs server time out of sync
StartTime: aws.Int64(time.Now().Add(-3*time.Minute).Unix() * 1000),
}
events, err := cw.GetLogEvents(get_log_input)
if err != nil {
return "", err
}
var output bytes.Buffer
for _, event := range events.Events {
output.WriteString(*event.Message)
}
return output.String(), nil
}
示例3: load
func load(logService *cloudwatchlogs.CloudWatchLogs, initial chan<- string, follow chan<- string, limit int, startTime time.Time, endTime time.Time, instanceId string, terminated bool) {
initialParams := &cloudwatchlogs.GetLogEventsInput{
LogGroupName: pointer.String(logGroupName),
LogStreamName: &instanceId,
}
if endTime.IsZero() {
if !startTime.IsZero() {
initialParams.StartFromHead = pointer.Bool(true)
initialParams.StartTime = pointer.Int64(startTime.UnixNano() / int64(time.Millisecond))
} else {
initialParams.EndTime = pointer.Int64(time.Now().UnixNano() / int64(time.Millisecond))
}
initialParams.Limit = pointer.Int64(int64(limit))
} else {
initialParams.StartFromHead = pointer.Bool(true)
initialParams.StartTime = pointer.Int64(startTime.UnixNano() / int64(time.Millisecond))
initialParams.EndTime = pointer.Int64(endTime.UnixNano() / int64(time.Millisecond))
}
logEvents, err := logService.GetLogEvents(initialParams)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", instanceId, err)
initial <- ""
return
}
for _, e := range logEvents.Events {
if *e.Message != "" {
initial <- formatMessage(e)
}
}
initial <- ""
if follow == nil || terminated {
return
}
token := logEvents.NextForwardToken
for {
logEvents, err := logService.GetLogEvents(&cloudwatchlogs.GetLogEventsInput{
LogGroupName: pointer.String(logGroupName),
LogStreamName: &instanceId,
NextToken: token,
StartFromHead: pointer.Bool(true),
})
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", instanceId, err)
continue
}
for _, e := range logEvents.Events {
follow <- formatMessage(e)
}
token = logEvents.NextForwardToken
time.Sleep(pollInterval)
}
}