graylogd

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

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

Go to latest
Published: May 3, 2018 License: MIT Imports: 11 Imported by: 0

README

graylog daemon in golang

graylogd is a implementation for serving messages in GELF(Graylog Extended Log Format) in golang

Example:

package main

import (
    "fmt"
    "net"

    "github.com/lintianzhi/graylogd"
)

func main() {
    conf := graylogd.Config{
        ListenAddr: ":12201",
        // handle raw message
        //HandleRaw: func(b []byte) {
        //  fmt.Println(string(b))
        //  fmt.Println(len(b))
        //},
        HandleGELF: func(gelf *graylogd.GelfLog, addi map[string]interface{}) {
            fmt.Println(gelf)
            fmt.Println(addi)
        },
        HandleError: func(addr *net.UDPAddr, err error) {
            fmt.Println("err:", err)
        },
    }

    logd, _ := graylogd.NewGraylogd(conf)
    err := logd.Run()
    if err != nil {
        fmt.Println("run failed:", err)
        return
    }
    select {}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ListenAddr string

	// handle raw message, HandleGELF wouldn't be called if HandleRaw is setted
	HandleRaw func([]byte)

	// handle GELF message
	HandleGELF func(*GelfLog, map[string]interface{})

	HandleError func(*net.UDPAddr, error)
}

type GelfLog

type GelfLog struct {
	Version   string  `json:"version"`
	Host      string  `json:"host"`
	ShortMsg  string  `json:"short_message"`
	FullMsg   string  `json:"full_message"`
	Timestamp float64 `json:"timestamp,string"`
	Level     int     `json:"level"`
	Facility  string  `json:"facility"`
	Line      int     `json:"line"`
	File      string  `json:"file"`
}

type Graylogd

type Graylogd struct {
	Config
	// contains filtered or unexported fields
}

func NewGraylogd

func NewGraylogd(conf Config) (srv *Graylogd, err error)

func (*Graylogd) Close

func (srv *Graylogd) Close() (err error)

func (*Graylogd) Run

func (srv *Graylogd) Run() (err error)

Jump to

Keyboard shortcuts

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