cloudwatchlogger

package module
v0.0.0-...-465b9c6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2016 License: MIT Imports: 18 Imported by: 0

README

CloudWatch Logger

a simple library for sending log entries to AWS CloudWatch logs.

Embedded Use

See full example.

Agent Use

A stand-alone agent is provided for easy logging scenarios. The AWS CloudWatch Logs Agent is a much more robust tool and should be considered.

./agent usage:
  -group string
    	cloudwatch group name (usually app name) **required**
  -stream string
    	cloudwatch stream name (usually host name) (default `hostname`)
  -flush_interval duration
    	cloudwatch batch flushing frequency (default 30s)
  -sock string
    	unix socket to listen on (default "/var/run/cwagent.sock")
  -stdin
    	read from STDIN instead of unix socket

The agent listens on STDIN, or a unix socket, for any input. Each newline terminated line is sent to CloudWatch logs. Any log group/stream that does not exist will be created on first use.

export AWS_REGION="xxx"
export AWS_ACCESS_KEY_ID="xxx"
export AWS_SECRET_ACCESS_KEY="xxx"

echo "log this!" | ./agent -group junklogs -stdin

# or as a daemon listening on unix socket
# (using `socat` for command line socket redirection, not required)
./agent -group junklogs -sock junk.sock &
[1234] agent
echo "log this too!" | socat - junk.sock

Production uses will redirect STDOUT/STDERR from running applications via monit, systemd, upstart, etc.

##LICENSE MIT

Documentation

Index

Constants

View Source
const (
	MaxMessageLength = 32 << 10
)

Variables

View Source
var (

	// this is how long a batch will continue to be retried, in the event CloudWatch is
	// not available.  At which point the batch is dumped to stderr
	MaxRetryTime = time.Hour

	// the buffer length of the log event channel
	EventLogBufferLength = 64 << 10

	// this occurs when the buffered channel receiving log writes blocks
	ErrStreamBackedUp = errors.New("stream backed up")
)
View Source
var (
	MaxSleepInterval = 10 * time.Second
	ErrMaxTries      = errors.New("max tries")
)

Functions

This section is empty.

Types

type Logger

type Logger struct {

	// Service exposed for direct actions
	Service *cloudwatchlogs.CloudWatchLogs

	Debug bool
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(sess *session.Session, group, stream string, flushInterval time.Duration) (*Logger, error)

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Write

func (l *Logger) Write(b []byte) (int, error)

func (*Logger) WriteError

func (l *Logger) WriteError(err error) error

func (*Logger) WriteJSON

func (l *Logger) WriteJSON(v interface{}) error

func (*Logger) WriteRoundTrip

func (l *Logger) WriteRoundTrip(resp *http.Response, duration time.Duration) error

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(n int, d time.Duration) *RateLimiter

func (*RateLimiter) Close

func (r *RateLimiter) Close()

func (*RateLimiter) Ready

func (r *RateLimiter) Ready() bool

type Trier

type Trier struct {
	// contains filtered or unexported fields
}

func NewTrier

func NewTrier(maxTotalTime time.Duration) *Trier

func (*Trier) Try

func (t *Trier) Try() bool

func (*Trier) TryFunc

func (t *Trier) TryFunc(f func() (error, bool)) error

func (*Trier) Wait

func (t *Trier) Wait()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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