https://github.com/halink0803/zerolog-graylog-hook
This is a hook to send log to graylog, support GELF
https://github.com/halink0803/zerolog-graylog-hook
hacktoberfest hacktoberfest2021
Last synced: 12 months ago
JSON representation
This is a hook to send log to graylog, support GELF
- Host: GitHub
- URL: https://github.com/halink0803/zerolog-graylog-hook
- Owner: halink0803
- License: mit
- Created: 2018-07-26T10:25:17.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-01T14:20:26.000Z (about 2 years ago)
- Last Synced: 2024-06-19T18:08:16.132Z (about 2 years ago)
- Topics: hacktoberfest, hacktoberfest2021
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graylog hook for [zerolog](https://github.com/rs/zerolog)
This is a hook to send log to graylog, support GELF.
## Usage
Sample code using graylog hook
```golang
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*