logrus_cloudwatchlogs_async

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

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 7 Imported by: 0

README

Asynchronous CloudWatch Logs hook for Logrus

Send Logrus logs to Amazon's CloudWatch Logs service.

Inspired by logrus-cloudwatchlogs, but it sends logs asynchronously, therefore it doesn't impair application performance. It can also handle the host temporarily going offline.

Example

package main

import (
	"os"

	"github.com/sirupsen/logrus"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/szemate/logrus-cloudwatchlogs-async"
)

func main() {
	key := os.Getenv("AWS_ACCESS_KEY")
	secret := os.Getenv("AWS_SECRET_KEY")
	group := os.Getenv("AWS_CLOUDWATCHLOGS_GROUP_NAME")
	stream := os.Getenv("AWS_CLOUDWATCHLOGS_STREAM_NAME")

	cred := credentials.NewStaticCredentials(key, secret, "")
	cfg := aws.NewConfig().WithRegion("us-east-1").WithCredentials(cred)

	logger := logrus.New()

	hook, err := logrus_cloudwatchlogs_async.NewHook(group, stream, cfg)
	if err != nil {
		logger.Fatal(err)
	}
	logger.Hooks.Add(hook)

	logger.Fatal("Some fatal event")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

func NewHook

func NewHook(groupName, streamName string, config *aws.Config) (*Hook, error)

func (*Hook) Fire

func (hook *Hook) Fire(entry *logrus.Entry) error

Implements logrus.Hook interface

func (*Hook) Levels

func (hook *Hook) Levels() []logrus.Level

Implements logrus.Hook interface

func (*Hook) StartSendingEvents

func (hook *Hook) StartSendingEvents()

func (*Hook) StopSendingEvents

func (hook *Hook) StopSendingEvents()

Jump to

Keyboard shortcuts

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