gelf

package module
v0.0.0-...-186f20e Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 3 Imported by: 0

README

GO: GELF implements Because of performance, I recommender to build your own TCP or UDP connection to send GELF data:

Quick use

import "github.com/duythinht/gelf"

Create message JSON

func main() {
  message := gelf.Create("Short message content")
              .SetTimestamp(time.Now().Unix())
              .SetFullMessage("This is full message")
              .SetLevel(3)
              .SetHost("chat Server")
              .ToJSON()
}

Zip message

import "github.com/duythinht/gelf/chunk"

func main() {
  // message := ... # JSON message
  buffer := chunk.ZipMessage(message)
}

Chunking message

import "github.com/duythinht/gelf/chunk"

func main() {
  // ZippedMessage := ... # type []byte
  if len(ZippedMessage) > MaxChunkSize) {
    buffers := chunk.GetGelfChunks(ZippedMessage, MaxChunkSize)
  }
}

BTW, I offer a UDP clients pool to send message to graylog (workers by goroutine):

import "github.com/duythinht/gelf/client"

c := client.New(client.Config{
  GraylogHost: "10.60.6.48",
  GraylogPort: 13000,
})

message := gelf.Create("...").ToJSON()

c.Send(message) 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct {
	Version      string `json:"version"`
	Host         string `json:"host"`
	ShortMessage string `json:"short_message"`
	FullMessage  string `json:"full_message"`
	Timestamp    int64  `json:"timestamp"`
	Level        int    `json:"level"`
}

func Create

func Create(message string) *Log

func (*Log) SetFullMessage

func (self *Log) SetFullMessage(fullMessage string) *Log

func (*Log) SetHost

func (self *Log) SetHost(host string) *Log

func (*Log) SetLevel

func (self *Log) SetLevel(level int) *Log

func (*Log) SetTimestamp

func (self *Log) SetTimestamp(timestamp int64) *Log

func (*Log) ToJSON

func (self *Log) ToJSON() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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