Skip to content
A structured logger for Fluentd (Golang)
Go
Branch: master
Clone or download
Latest commit cca4fbf Aug 15, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_examples
fluent
.gitignore change main source directory May 16, 2013
.travis.yml msgp 1.8 no longer supports golang 1.8 Aug 14, 2019
CHANGELOG.md v1.4.0 Dec 11, 2018
LICENSE update LICENSE with full Apache License 2.0 text Feb 5, 2016
README.md v1.4.0 Dec 11, 2018

README.md

fluent-logger-golang

Build Status

A structured event logger for Fluentd (Golang)

How to install

go get github.com/fluent/fluent-logger-golang/fluent

Usage

Install the package with go get and use import to include it in your project.

import "github.com/fluent/fluent-logger-golang/fluent"

GoDoc: http://godoc.org/github.com/fluent/fluent-logger-golang/fluent

Example

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.

Setting config values

f := fluent.New(fluent.Config{FluentPort: 80, FluentHost: "example.com"})

WriteTimeout

Sets the timeout for Write call of logger.Post. Since the default is zero value, Write will not time out.

Async

Enable asynchronous I/O (connect and write) for sending events to Fluentd. The default is false.

RequestAck

Sets whether to request acknowledgment from Fluentd to increase the reliability of the connection. The default is false.

Tests

go test
You can’t perform that action at this time.