Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBatchIntervalTooSmall = errors.New("batch interval is too small")
ErrBatchIntervalTooSmall is returned when the batch interval is too small.
var ErrFullOrClosed = errors.New("cannot create new event: channel full or closed")
ErrFullOrClosed is returned when the payloads channel is full or closed via close().
Functions ¶
This section is empty.
Types ¶
type CloudWatchLogsClient ¶
type CloudWatchLogsClient interface { DescribeLogStreams(context.Context, *cloudwatchlogs.DescribeLogStreamsInput, ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.DescribeLogStreamsOutput, error) CreateLogGroup(context.Context, *cloudwatchlogs.CreateLogGroupInput, ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.CreateLogGroupOutput, error) CreateLogStream(context.Context, *cloudwatchlogs.CreateLogStreamInput, ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.CreateLogStreamOutput, error) PutLogEvents(context.Context, *cloudwatchlogs.PutLogEventsInput, ...func(*cloudwatchlogs.Options)) (*cloudwatchlogs.PutLogEventsOutput, error) }
CloudWatchLogsClient represents the AWS cloudwatchlogs client that we need to talk to CloudWatch
type CloudWatchWriter ¶
type CloudWatchWriter struct { Stats Stats // contains filtered or unexported fields }
CloudWatchWriter can be inserted into zerolog to send logs to CloudWatch.
func NewWithClient ¶
func NewWithClient(client CloudWatchLogsClient, batchInterval time.Duration, logGroupName, logStreamName string) (*CloudWatchWriter, error)
NewWithClient does the same as NewWithClientContext but uses context.Background() as the context.
func NewWithClientContext ¶ added in v1.4.0
func NewWithClientContext(ctx context.Context, client CloudWatchLogsClient, batchInterval time.Duration, logGroupName, logStreamName string) (*CloudWatchWriter, error)
NewWithClientContext creates a new CloudWatchWriter with the given client, batch interval, log group name and log stream name. Use Close method to properly close the writer. The writer will not accept any new events after Close is called. The writer will flush the buffer and close the payloads channel when Close is called. Use context cancellation to stop the writer and Close to properly close it.
func (*CloudWatchWriter) Close ¶
func (c *CloudWatchWriter) Close()
Close will flush the buffer, close the channel and wait until all payloads are sent, not longer than 2 seconds. It is safe to call close multiple times. After close is called the client will not accept any new events, all attemtps to send new events will return ErrFullOrClosed.
func (*CloudWatchWriter) Flush ¶ added in v1.4.0
func (c *CloudWatchWriter) Flush()
Flush will cause the logger to flush the current buffer. It does not block, there is no guarantee that the buffer will be flushed immediately. Use Close in order to properly close during application termination.
type Handler ¶ added in v1.4.1
type Handler struct { *slog.JSONHandler // contains filtered or unexported fields }
Handler is a slog.Handler that sends logs to AWS CloudWatch.
func NewHandler ¶ added in v1.4.1
func NewHandler(config HandlerConfig) (*Handler, error)
NewHandler creates a new log/slog handler.
type HandlerConfig ¶ added in v1.4.1
type HandlerConfig struct { // Level is the logging level for this output. Level slog.Leveler // AddSource is a flag to add source to the log record. AddSource bool // AWSRegion is the AWS region. AWSRegion string // AWSKey is the AWS access key. AWSKey string // AWSSecret is the AWS secret key. AWSSecret string // AWSSession is an optional AWS session token. AWSSession string // AWSLogGroup is the AWS CloudWatch log group. AWSLogGroup string // AWSLogStream is the AWS CloudWatch log stream. AWSLogStream string }
HandlerConfig is the configuration for the Cloudwatch handler.
type Stats ¶ added in v1.4.0
type Stats struct { // Total number of events queued for sending QueuedEventCount atomic.Uint64 // Total number of events sent (EventsEnqueued >= SentEventCount) SentEventCount atomic.Uint64 // Total number of requests sent BatchCount atomic.Uint64 // Total number of HTTP retries RetryCount atomic.Uint64 }