logrus_amqp

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

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

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 3 Imported by: 2

README

AMQP Hook for Logrus

Usage

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/vladoatanasov/logrus_amqp"
)

func main() {
	log := logrus.New()
  
  	hook := logrus_amqp.NewAMQPHook("127.0.0.1:5672", "guest", "guest", "exchange-rabbitmq", "routing-key")
	// with virtual host
	hook := logrus_amqp.NewAMQPHookWithType("127.0.0.1:5672", "guest", "guest", "exchange-rabbitmq", "virtualHost" "routing-key")
	
	log.Hooks.Add(hook)
	
}

func doWork() {
  err := some_useful_func()
  
  if err != nil {
		log.WithFields(logrus.Fields{
			"topic": "some_useful_func",
		}).Error(err)
	}
}

With this hook, you can easily send logs to the ELK stack, using rabbitmq as a message broker. You can find a working docker-compose project here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AMQPHook

type AMQPHook struct {
	AMQPServer   string
	Username     string
	Password     string
	Exchange     string
	ExchangeType string
	RoutingKey   string
	VirtualHost  string
	Mandatory    bool
	Immediate    bool
	Durable      bool
	Internal     bool
	NoWait       bool
	AutoDeleted  bool
}

func NewAMQPHook

func NewAMQPHook(server, username, password, exchange, routingKey string) *AMQPHook

func NewAMQPHookWithType

func NewAMQPHookWithType(server, username, password, exchange, exchangeType, virtualHost, routingKey string) *AMQPHook

func (*AMQPHook) Fire

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

Fire is called when an event should be sent to the message broker

func (*AMQPHook) Levels

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

Levels is available logging levels.

Jump to

Keyboard shortcuts

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