cloudwriter

package module
v0.0.0-...-f6d8941 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

README

cloudwriter

Build Status GoDoc

cloudwriter is a implementation of io.Writer that ships data to AWS CloudWatch

Example

Assuming that you've set AWS credentials via the environment, the following example writes logs messages to the sample-group cloudwatch log group.

package main

import (
	"io"
	"log"
	"time"

	"github.com/savaki/cloudwriter"
)

func main() {
	w, err := cloudwriter.New(nil, "sample-group", "sample-stream-{{.Timestamp}}",
	  cloudwriter.BatchSize(1)
	)
	if err != nil {
		log.Fatalln(err)
	}
	defer w.Close()

	io.WriteString(w, "hello world\n")
	io.WriteString(w, "the time has come the walrus said\n")
	io.WriteString(w, "to speak of many things\n")

	time.Sleep(time.Second) // pause to give the async cloudwriter time to write
}

Documentation

Index

Constants

View Source
const (
	// Maximum number of records to be saved before calling PutLogEvents
	MaxBatchSize = 1000

	// Default number of records to be saved before calling PutLogEvents
	DefaultBatchSize = 1000

	// Length of time to wait with no new records before shipping what records we have
	DefaultTimeout = time.Second * 15
)
View Source
const (
	ResourceAlreadyExistsException = "ResourceAlreadyExistsException"
)

Variables

This section is empty.

Functions

func BatchSize

func BatchSize(batchSize int) func(*logger)

The default batch size is MaxBatchSize. While this should be suitable for most cases, you have the option of changing this.

func Debug

func Debug(debug func(...interface{})) func(*logger)

func Interval

func Interval(t time.Duration) func(*logger)

func New

func New(client CloudWatchLogs, groupName, streamName string, configs ...func(*logger)) (io.WriteCloser, error)

New instantiates a new io.WriteCloser instance that asynchronously writes records to CloudWatchLogs. cloudwriter assumes that records will be divided using a newline character.

client is an optional instance of *cloudwatchlogs.CloudWatchLogs

streamName supports go template style interpolation with {{ .Timestamp }}

func WithBatchSize

func WithBatchSize(w io.WriteCloser, batchSize int) io.WriteCloser

The default batch size is MaxBatchSize. While this should be suitable for most cases, you have the option of changing this.

func WithDebug

func WithDebug(w io.WriteCloser, debug func(...interface{})) io.WriteCloser

For testing, enables debug messages to be printed.

Types

type CloudWatchLogs

CloudWatchLogs is an interface that provides the minimal shape of *cloudwatchlogs.CloudWatchLogs and simplifies testing

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL