go get github.com/fluent/fluent-logger-golang/fluent
Install the package with go get
and use import
to include it in your project.
import "github.com/fluent/fluent-logger-golang/fluent"
package main
import (
"github.com/fluent/fluent-logger-golang/fluent"
"fmt"
//"time"
)
func main() {
logger, err := fluent.New(fluent.Config{})
if err != nil {
fmt.Println(err)
}
defer logger.Close()
tag := "myapp.access"
var data = map[string]string{
"foo": "bar",
"hoge": "hoge",
}
error := logger.Post(tag, data)
// error := logger.PostWithTime(tag, time.Now(), data)
if error != nil {
panic(error)
}
}
data
must be a value like map[string]literal
, map[string]interface{}
, struct
or msgp.Marshaler
. Logger refers tags msg
or codec
of each fields of structs.
f := fluent.New(fluent.Config{FluentPort: 80, FluentHost: "example.com"})
Sets the timeout for Write call of logger.Post. Since the default is zero value, Write will not time out.
Enable asynchronous I/O (connect and write) for sending events to Fluentd. The default is false.
When Async is enabled, immediately discard the event queue on close() and return (instead of trying MaxRetry times for each event in the queue before returning) The default is false.
Sets whether to request acknowledgment from Fluentd to increase the reliability of the connection. The default is false.
"the features" includes heartbeat messages (for TCP keepalive), TLS transport and shared key authentication.
This logger doesn't support those features. Patches are welcome!
go test