cwlogger

package
v0.0.0-...-69f65aa Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0, MIT Imports: 13 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The Amazon CloudWatch Logs client created with the AWS SDK for Go.
	// Required.
	Client *cloudwatchlogs.Client

	// The name of the log group to write logs into. Required.
	LogGroupName string

	// An optional function to report errors that couldn't be automatically
	// handled during a PutLogEvents API call and caused a log events to be
	// dropped.
	ErrorReporter func(err error)

	// An optional log group retention time in days. This value is only taken into
	// account when creating a log group that does not yet exist. Set to 0
	// (default) for no retention policy. Refer to the PutRetentionPolicy API
	// documentation for valid values.
	Retention int
}

The Config for the Logger.

type Error

type Error struct {
	Code    string
	Message string
}

Error contains the AWS error code and message that caused the PutLogEvents action to fail. Errors reported by the LogGroup ErrorReporter function may be converted into this type.

func (Error) Error

func (err Error) Error() string

type Logger

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

A Logger represents a single CloudWatch Logs log group.

func New

func New(config *Config) (*Logger, error)

New creates a new Logger.

Creates the log group if it doesn't yet exist, and one initial log stream for writing logs into.

Returns an error if the configuration is invalid, or if either the creation of the log group or log stream fail.

func (*Logger) Close

func (lg *Logger) Close()

Close drains all enqueued log messages and writes them to CloudWatch Logs. This method blocks until all pending log messages are written.

The Logger is not meant to be used anymore after this method is called. Doing so will result in a panic. Create a new Logger if you wish to write more logs.

func (*Logger) Log

func (lg *Logger) Log(t time.Time, s string)

Log enqueues a log message to be written to a log stream.

The log message must be less than 1,048,550 bytes, and the time must not be more than 2 hours in the future, 14 days in the past, or older than the retention period of the log group.

This method is safe for concurrent access by multiple goroutines.

Jump to

Keyboard shortcuts

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