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


Golang cloudwatchlogs.CloudWatchLogs类代码示例

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


在下文中一共展示了CloudWatchLogs类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:nickschuch,项目名称:cloudwatch-cli,代码行数:32,代码来源:aws.go

示例2: 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

示例3: streams

func streams(svc *cloudwatchlogs.CloudWatchLogs, g string) ([]string, error) {
	var streams []string

	params := &cloudwatchlogs.DescribeLogStreamsInput{
		LogGroupName: aws.String(g),
	}
	resp, err := svc.DescribeLogStreams(params)
	if err != nil {
		return streams, err
	}

	for _, l := range resp.LogStreams {
		streams = append(streams, *l.LogStreamName)
	}

	return streams, nil
}
开发者ID:nickschuch,项目名称:cloudwatch-cli,代码行数:17,代码来源:aws.go

示例4: findLogStreamsSince

func findLogStreamsSince(logService *cloudwatchlogs.CloudWatchLogs, startTime time.Time, endTime time.Time, output chan<- stream) {
	var (
		startTimestamp = startTime.UnixNano() / 1000000
		endTimestamp   = endTime.UnixNano() / 1000000
	)

	go func() {
		defer close(output)

		var nextToken *string

		for {
			logStreams, err := logService.DescribeLogStreams(&cloudwatchlogs.DescribeLogStreamsInput{
				Descending:   pointer.Bool(true),
				LogGroupName: pointer.String(logGroupName),
				NextToken:    nextToken,
				OrderBy:      pointer.String("LastEventTime"),
			})
			if err != nil {
				panic(err)
			}

			for _, logStream := range logStreams.LogStreams {
				fmt.Fprintf(os.Stderr, "%s...%s %s\n", time.Unix(0, *logStream.FirstEventTimestamp*1000000), time.Unix(0, *logStream.LastEventTimestamp*1000000), *logStream.LogStreamName)

				if endTimestamp > 0 && *logStream.FirstEventTimestamp > endTimestamp {
					continue
				}

				if *logStream.LastEventTimestamp < startTimestamp {
					return
				}

				output <- stream{
					name: *logStream.LogStreamName,
				}
			}

			nextToken = logStreams.NextToken
		}
	}()

	return
}
开发者ID:ninchat,项目名称:awslogtail,代码行数:44,代码来源:awslogtail.go

示例5: flattenCloudWatchTags

func flattenCloudWatchTags(d *schema.ResourceData, conn *cloudwatchlogs.CloudWatchLogs) (map[string]interface{}, error) {
	tagsOutput, err := conn.ListTagsLogGroup(&cloudwatchlogs.ListTagsLogGroupInput{
		LogGroupName: aws.String(d.Get("name").(string)),
	})
	if err != nil {
		return nil, errwrap.Wrapf("Error Getting CloudWatch Logs Tag List: %s", err)
	}
	if tagsOutput != nil {
		output := make(map[string]interface{}, len(tagsOutput.Tags))

		for i, v := range tagsOutput.Tags {
			output[i] = *v
		}

		return output, nil
	}

	return make(map[string]interface{}), nil
}
开发者ID:hashicorp,项目名称:terraform,代码行数:19,代码来源:resource_aws_cloudwatch_log_group.go

示例6: lookupCloudWatchLogMetricFilter

func lookupCloudWatchLogMetricFilter(conn *cloudwatchlogs.CloudWatchLogs,
	name, logGroupName string, nextToken *string) (*cloudwatchlogs.MetricFilter, error) {

	input := cloudwatchlogs.DescribeMetricFiltersInput{
		FilterNamePrefix: aws.String(name),
		LogGroupName:     aws.String(logGroupName),
		NextToken:        nextToken,
	}
	log.Printf("[DEBUG] Reading CloudWatch Log Metric Filter: %s", input)
	resp, err := conn.DescribeMetricFilters(&input)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" {
			return nil, &resource.NotFoundError{
				Message: fmt.Sprintf("CloudWatch Log Metric Filter %q / %q not found via"+
					" initial DescribeMetricFilters call", name, logGroupName),
				LastError:   err,
				LastRequest: input,
			}
		}

		return nil, fmt.Errorf("Failed describing CloudWatch Log Metric Filter: %s", err)
	}

	for _, mf := range resp.MetricFilters {
		if *mf.FilterName == name {
			return mf, nil
		}
	}

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

	return nil, &resource.NotFoundError{
		Message: fmt.Sprintf("CloudWatch Log Metric Filter %q / %q not found "+
			"in given results from DescribeMetricFilters", name, logGroupName),
		LastResponse: resp,
		LastRequest:  input,
	}
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:40,代码来源:resource_aws_cloudwatch_log_metric_filter.go

示例7: 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

示例8: lookupCloudWatchLogStream

func lookupCloudWatchLogStream(conn *cloudwatchlogs.CloudWatchLogs,
	name string, logStreamName string, nextToken *string) (*cloudwatchlogs.LogStream, bool, error) {
	input := &cloudwatchlogs.DescribeLogStreamsInput{
		LogStreamNamePrefix: aws.String(name),
		LogGroupName:        aws.String(logStreamName),
		NextToken:           nextToken,
	}
	resp, err := conn.DescribeLogStreams(input)
	if err != nil {
		return nil, true, err
	}

	for _, ls := range resp.LogStreams {
		if *ls.LogStreamName == name {
			return ls, true, nil
		}
	}

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

	return nil, false, nil
}
开发者ID:partamonov,项目名称:terraform,代码行数:24,代码来源:resource_aws_cloudwatch_log_stream.go

示例9: 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

示例10: 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)
	}
}
开发者ID:ninchat,项目名称:awslogtail,代码行数:63,代码来源:awslogtail.go


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