cloudwatchlogs

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: GPL-2.0 Imports: 15 Imported by: 0

README

AWS CloudWatch Logs Client

This go package allows read/write operations from CloudWatch Logs.

Usage

Read Logs
import (
    "github.com/previousnext/go-cloudwatchlogs"
    "github.com/aws/aws-sdk-go/aws"
)

params := cloudwatchlogs.QueryParams{
    Group:  "loggroup-name",
    Prefix: "logstream-name",
    Start:  aws.TimeUnixMilli(time.Now().Add(-startDuration).UTC()),
    End:    aws.TimeUnixMilli(time.Now().Add(-endDuration).UTC()),
}

resp, err := cloudwatchlogs.Query(client, params)
if err != nil {
    panic(err)
}

for _, log := range resp.Logs {
    fmt.Printf("%s | %s", log.Stream, log.Message)
}
Write Logs
import "github.com/previousnext/go-cloudwatchlogs"

file := os.Open("/var/log/containers/path-to.log")
params := cloudwatchlogs.StreamParams{
    // AWS CloudWatch region. 
    Region:      "us-east-1",
    // Directory where logs are located.
    Directory:   "/var/log/containers",
    // Prefix to apply to loggroup.
    Prefix:      "",
    // Regex pattern to use for excluding certain log messages.
    SkipPattern: "",
    // File handler.
    File:        file,
    // Whether this is a new or existing file.
    New:         false,
}
err := cloudwatchlogs.Stream(params)
if err != nil {
    log.Errorf("Failed to stream existing file: %s: %s", file.Name(), err)
} else {
    log.Infof("Finished streaming existing file: %s", file.Name())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stream

func Stream(params StreamParams) error

Stream the contents of a file to CloudWatch Logs.

Types

type Log

type Log struct {
	Stream    string
	Timestamp int64
	Message   string
}

Log which contains messages from streams.

type Message

type Message struct {
	Log    string    `json:"log"`
	Stream string    `json:"stream"`
	Time   time.Time `json:"time"`
}

Message is for each line in a Docker container log file.

type QueryOutput

type QueryOutput struct {
	Logs []Log
}

QueryOutput which gets returned fromm Query function.

func Query

func Query(client *cloudwatchlogs.CloudWatchLogs, params QueryParams) (QueryOutput, error)

Query for logs.

type QueryParams

type QueryParams struct {
	Group  string
	Prefix string
	Start  int64
	End    int64
}

QueryParams which get passed to the Query function.

type StreamParams

type StreamParams struct {
	Region      string
	Directory   string
	Prefix      string
	SkipPattern string
	File        os.FileInfo
	New         bool
}

StreamParams passed into the Stream function.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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