udploghook

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

README

UDPLog Logrus Hook

A Logrus Hook for sending log info to UDPLog

Usage

import (
    "github.com/sirupsen/logrus"
    "github.com/mailgun/logrus-hooks/udploghook"
)

hook, err := udploghook.New("localhost", 55647)
if err != nil {
    panic(err)
}

// Tell logrus about the hook
logrus.AddHook(hook)

// Log a line
logrus.Info("Your mother milk chicken for a living")

will result in json

{
	"context": null,
	"appname": "logrus-udplog.test",
	"hostname": "localhost",
	"logLevel": "INFO",
	"filename": "/mailgun/logrus-udplog/functional_test.go",
	"funcName": "github.com/mailgun/logrus-udplog_test.(*FunctionalTest).TestUDPHookExported",
	"lineno": 55,
	"message": "Your mother milk chicken for a living",
	"timestamp": 1485482245.473685
}

logrus.WithFields() places the fields into the context object.

log.WithFields(logrus.Fields{
	"domain.id": "282b0862-e425-11e6-a897-600308a97d8c",
	"domain.name": "example.com",
	"bar": "foo",
	"foo.bar": "bar",
}).Error("Your mother milk chicken for a living")

will result in json

{
    "context": {
        "domain": {
            "id": "282b0862-e425-11e6-a897-600308a97d8c",
            "name": "example.com"
        },
        "bar": "foo",
        "foo": {
            "bar": "bar"
        }
    },
	"appname": "logrus-udplog.test",
	"hostname": "localhost",
	"logLevel": "INFO",
	"filename": "/mailgun/logrus-udplog/functional_test.go",
	"funcName": "github.com/mailgun/logrus-udplog_test.(*FunctionalTest).TestUDPHookContext",
	"lineno": 75,
	"message": "Your mother milk chicken for a living",
	"timestamp": 1485482245.472957
}

logrus.WithFields() also understands http.Request objects

func (c *Controller) Get(w http.ResponseWriter, r *http.Request) (interface{}, error) {
        log.WithFields{logrus.Fields{ "http": r, }).Info("Get Called")
}

will result in json

{
    "context": {
        "http": {
            "headers": {
                "User-Agent": ["test-agent"]
            },
            "ip": "192.0.2.1:1234",
            "method": "POST",
            "params": {
                "param1": ["1"],
                "param2": ["2"]
            },
            "size": 4,
            "url": "http://example.com?param1=1&param2=2",
            "useragent": "test-agent"
        }
    },
	"appname": "logrus-udplog.test",
	"hostname": "localhost",
	"logLevel": "INFO",
	"filename": "/mailgun/logrus-udplog/functional_test.go",
	"funcName": "github.com/mailgun/logrus-udplog_test.(*FunctionalTest).TestUDPHookContext",
	"lineno": 175,
	"message": "Get Called",
	"timestamp": 1485482245.472957
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Test UDP Server

func NewServer

func NewServer(host string, port int) (*Server, error)

func (*Server) Close

func (udp *Server) Close()

func (*Server) GetRequest

func (udp *Server) GetRequest() map[string]interface{}

func (*Server) Host

func (udp *Server) Host() string

func (*Server) Port

func (udp *Server) Port() int

type UDPHook

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

func New

func New(host string, port int) (*UDPHook, error)

func (*UDPHook) Fire

func (h *UDPHook) Fire(entry *logrus.Entry) error

func (*UDPHook) Levels

func (h *UDPHook) Levels() []logrus.Level

Levels returns the available logging levels.

func (*UDPHook) SendIO

func (h *UDPHook) SendIO(input io.Reader) error

Given an io reader send the contents of the reader to udplog

func (*UDPHook) SetDebug

func (h *UDPHook) SetDebug(set bool)

Jump to

Keyboard shortcuts

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