Skip to content

halink0803/zerolog-graylog-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Graylog hook for zerolog

This is a hook to send log to graylog, support GELF.

Usage

Sample code using graylog hook

import (
    "github.com/halink0803/zerolog-graylog-hook/graylog"
    "github.com/rs/zerolog"
    "github.com/rs/zerolog/log"
)

func main() {
    // set default logger to print to stdout and prettify    
	log.Logger = zerolog.New(os.Stdout).With().Timestamp().Caller().Logger().Output(zerolog.ConsoleWriter{Out: os.Stderr})  
    // udp://127.0.0.1:12201 is log udp url 
	hook, err := graylog.NewGraylogHook("udp://127.0.0.1:12201")
	if err != nil {
		panic(err)
    }
    //Set global logger with graylog hook
    log.Logger = log.Hook(hook)
    
    // Print and send sample log
    for range time.Tick(time.Millisecond * 200) {
		for range time.Tick(time.Millisecond * 200) {
			log.Info.Msg("info log")
            log.Warn.Msg("warning log")
            log.Debug.Msg("debug log")
		}
	}
}

Note: When you first install Graylog, remember to go to /system/inputs to enable GELF input

About

This is a hook to send log to graylog, support GELF

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages