fluent-logger-golang

A structured logger for Fluentd (Golang)

Github stars Tracking Chart

fluent-logger-golang

Build Status
GoDoc

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"

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.

ForceStopAsyncSend

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.

RequestAck

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

FAQ

Does this logger support the features of Fluentd Forward Protocol v1?

"the features" includes heartbeat messages (for TCP keepalive), TLS transport and shared key authentication.

This logger doesn't support those features. Patches are welcome!

Tests

go test

Main metrics

Overview
Name With Ownerfluent/fluent-logger-golang
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:Apache License 2.0
所有者活动
Created At2013-04-10 05:56:04
Pushed At2023-09-11 10:25:53
Last Commit At2021-12-22 21:28:33
Release Count33
Last Release Namev1.9.0 (Posted on 2021-12-22 21:31:44)
First Release Namev0.0.1 (Posted on 2013-04-10 17:09:33)
用户参与
Stargazers Count391
Watchers Count18
Fork Count104
Commits Count246
Has Issues Enabled
Issues Count52
Issue Open Count18
Pull Requests Count51
Pull Requests Open Count4
Pull Requests Close Count22
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private