当前位置: 首页>>代码示例>>Golang>>正文


Golang CloudWatchLogs.DescribeLogGroups方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/cloudwatchlogs.CloudWatchLogs.DescribeLogGroups方法的典型用法代码示例。如果您正苦于以下问题:Golang CloudWatchLogs.DescribeLogGroups方法的具体用法?Golang CloudWatchLogs.DescribeLogGroups怎么用?Golang CloudWatchLogs.DescribeLogGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/cloudwatchlogs.CloudWatchLogs的用法示例。


在下文中一共展示了CloudWatchLogs.DescribeLogGroups方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cmdList

// To be used when no Group or Stream is provided. Will point the user to a group
// they can use for future runs.
func cmdList(svc *cloudwatchlogs.CloudWatchLogs) {
	params := &cloudwatchlogs.DescribeLogGroupsInput{}
	resp, err := svc.DescribeLogGroups(params)
	if err != nil {
		panic(err)
	}

	for _, l := range resp.LogGroups {
		fmt.Println(*l.LogGroupName)
	}
}
开发者ID:nickschuch,项目名称:cloudwatch-cli,代码行数:13,代码来源:main.go

示例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
}
开发者ID:iron-io,项目名称:lambda,代码行数:53,代码来源:lambda.go

示例3: lookupCloudWatchLogGroup

func lookupCloudWatchLogGroup(conn *cloudwatchlogs.CloudWatchLogs,
	name string, nextToken *string) (*cloudwatchlogs.LogGroup, error) {
	input := &cloudwatchlogs.DescribeLogGroupsInput{
		LogGroupNamePrefix: aws.String(name),
		NextToken:          nextToken,
	}
	resp, err := conn.DescribeLogGroups(input)
	if err != nil {
		return nil, err
	}

	for _, lg := range resp.LogGroups {
		if *lg.LogGroupName == name {
			return lg, nil
		}
	}

	if resp.NextToken != nil {
		return lookupCloudWatchLogGroup(conn, name, resp.NextToken)
	}

	return nil, fmt.Errorf("CloudWatch Log Group %q not found", name)
}
开发者ID:ewdurbin,项目名称:terraform,代码行数:23,代码来源:resource_aws_cloudwatch_log_group.go


注:本文中的github.com/aws/aws-sdk-go/service/cloudwatchlogs.CloudWatchLogs.DescribeLogGroups方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。