https://github.com/aphistic/golf
Client library written in Go for sending messages to Graylog Extended Log Format (GELF) servers. Allows per-message and global attributes to be attached to messages.
https://github.com/aphistic/golf
Last synced: 10 months ago
JSON representation
Client library written in Go for sending messages to Graylog Extended Log Format (GELF) servers. Allows per-message and global attributes to be attached to messages.
- Host: GitHub
- URL: https://github.com/aphistic/golf
- Owner: aphistic
- License: mit
- Created: 2015-08-24T00:45:41.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-07-12T15:58:19.000Z (almost 8 years ago)
- Last Synced: 2025-03-01T04:32:17.770Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 8
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
golf
====
[](https://godoc.org/github.com/aphistic/golf)
[](https://travis-ci.org/aphistic/golf)
[](http://codecov.io/github/aphistic/golf?branch=master)
Golf is an MIT-licensed Go client library for servers supporting the Graylog
Extended Log Format (GELF, https://www.graylog.org/resources/gelf-2/).
If you run into any issues with the library or have any feature requests, please create issues for them!
As this library is very new, the API could still change. I don't expect it to change much because I'm pretty happy with how it is now but if anyone has suggestions easier ways to use the library via API changes I would be open to it.
Test coverage is an ongoing process!
Features
========
* GELF 1.1 support
* Native Go implementation
* Supports Logger-level and Message-level attributes
Installation
============
The recommended way to install is via http://gopkg.in
go get gopkg.in/aphistic/golf.v0
...
import "gopkg.in/aphistic/golf.v0"
Golf can also be installed the standard way as well
go get github.com/aphistic/golf
...
import "github.com/aphistic/golf"
Examples
========
For brevity a lot of error checking has been omitted from these examples, be sure you do your checks!
The standard way to implement the golf library is by creating a Client, connecting to a server and creating Loggers off that Client:
```go
package main
import (
"gopkg.in/aphistic/golf.v0"
)
func main() {
c, _ := golf.NewClient()
c.Dial("udp://192.168.30.150")
l, _ := c.NewLogger()
// Attributes set at the Logger level will automatically be included
// on each message sent from that Logger. This is helpful if there's
// any consistent information you don't want to include every time you
// log a message.
l.SetAttr("facility", "golf.example")
l.SetAttr("instance_id", 12345)
for idx := 1; idx <= 10; idx++ {
l.Dbgm(map[string]interface{}{
"msg_attr1": 1234,
}, "Test message %v", idx)
}
c.Close()
}
```
It is also possible to set a Logger as the default for the golf library so you don't need to keep track of a main Logger manually:
```go
package main
import (
"gopkg.in/aphistic/golf.v0"
)
func main() {
c, _ := golf.NewClient()
c.Dial("udp://192.168.30.150")
l, _ := c.NewLogger()
// Set l as the default logger
golf.DefaultLogger(l)
// Attributes set at the Logger level will automatically be included
// on each message sent from that Logger. This is helpful if there's
// any consistent information you don't want to include every time you
// log a message.
l.SetAttr("facility", "golf.example")
l.SetAttr("instance_id", 12345)
for idx := 1; idx <= 10; idx++ {
// Use the default logger to send the message
golf.Dbgm(map[string]interface{}{
"msg_attr1": 1234,
}, "Test message %v", idx)
}
c.Close()
}
```
You can use the query parameter "compress" in the Dial URL, with one of the following value:
* none
* zlib
* gzip
```
udp://192.168.30.150?compress=none
```
Default is gzip compression.