zapcloudwatch2

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

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 8 Imported by: 0

README

Cloudwatch core for zap

Amazon AWS Cloudwatch core for zap logging library. Sends logs in batches using the official AWS Go SDK v2. The batch frequency is configurable and defaults to 2 seconds. AWS API limits apply:

  • The maximum batch size is 1 MiB or 10,000 events (the code takes care of this).
  • Maximum 5 requests per second per log stream (thus frequency cannot be higher than every 200ms).
  • Not older than 2 weeks or the retention period.
  • Not more than 2 hours in the future (get your system time and zone right).
  • Events in a batch must not span more than 24 hours.

Example

All you need is AWS region, key secret, token and frequency (> 200ms), then use zap logging library as usual. One important thing is to call Sync before your program exists otherwise buffered events will not be sent. You can use defer in the main function to ensure this even when program panics.

See this example

Install

$ go get -u github.com/lzap/zapcloudwatch2

## Wait

Yes my nick is and has always been lzap and the logging library is zap. This github organization name has nothing to do with zap or Uber, it is just my personal account.

Authors

Documentation

Index

Constants

This section is empty.

Variables

AllLevels Supported log levels

Functions

func LevelThreshold

func LevelThreshold(l zapcore.Level) []zapcore.Level

LevelThreshold - Returns every logging level above and including the given parameter.

func NewCloudwatchCore

func NewCloudwatchCore(params *NewCloudwatchCoreParams) (zapcore.Core, error)

Types

type CloudwatchCore

type CloudwatchCore struct {
	AcceptedLevels []zapcore.Level
	GroupName      string
	StreamName     string
	Config         *aws.Config
	BatchFrequency time.Duration

	zapcore.LevelEnabler
	// contains filtered or unexported fields
}

func (*CloudwatchCore) Check

func (*CloudwatchCore) Levels

func (c *CloudwatchCore) Levels() []zapcore.Level

Levels sets which levels to sent to cloudwatch

func (*CloudwatchCore) Sync

func (c *CloudwatchCore) Sync() error

func (*CloudwatchCore) With

func (c *CloudwatchCore) With(fields []zapcore.Field) zapcore.Core

func (*CloudwatchCore) Write

func (c *CloudwatchCore) Write(ent zapcore.Entry, fields []zapcore.Field) error

type NewCloudwatchCoreParams

type NewCloudwatchCoreParams struct {
	GroupName    string
	StreamName   string
	Config       *aws.Config
	AWSRegion    string
	AWSAccessKey string
	AWSSecretKey string
	AWSToken     string
	Level        zapcore.Level
	Enc          zapcore.Encoder
	Out          zapcore.WriteSyncer
	LevelEnabler zapcore.LevelEnabler
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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