fluent

package module
v0.0.0-...-59ff434 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2020 License: MIT Imports: 6 Imported by: 0

README

fluent-logger-go

Goroutine based asynchronous event logger for Fluentd

Project status

Not maintained. Please use fluent/fluent-logger-golang instead.

Features

  • Channel based non-blocking logging interface
  • Queued events are periodically sent to fluentd altogether

Installation

$ go get github.com/k0kubun/fluent-logger-go

Usage

package main

import "github.com/gin-gonic/gin"
import "github.com/k0kubun/fluent-logger-go"

var logger *fluent.Logger

func logId(c *gin.Context) {
	id := c.Params.ByName("id")
	logger.Post("idlog", map[string]string{"id": id})
	c.String(200, "Logged id")
}

func main() {
	logger = fluent.NewLogger(fluent.Config{})
	r := gin.Default()
	r.GET("/:id", logId)
	r.Run(":3000")
}
Documentation

API documentation can be found here: https://godoc.org/github.com/k0kubun/fluent-logger-go

You would like to use another one for some use case.

Documentation

Index

Constants

View Source
const (
	DefaultFluentHost            = "127.0.0.1"
	DefaultFluentPort            = 24224
	DefaultChannelLength         = 1000
	DefaultBufferLength          = 10 * 1024
	DefaultMaxTrialForConnection = 10
	DefaultConnectionTimeout     = 3 * time.Second
	DefaultBufferingTimeout      = 100 * time.Millisecond
	DefaultTagPrefix             = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// You can customize fluentd host and port.
	FluentHost string
	FluentPort int

	// If buffered channel's length is equal to ChannelLength, main thread blocks.
	ChannelLength int

	// If all posted messages' size reaches BufferLength, logger flushes all logs.
	BufferLength int

	// Retry connection with fluentd MaxTrialForConnection times.
	MaxTrialForConnection int

	// Wait for connection until ConnectionTimeout.
	ConnectionTimeout time.Duration

	// Logger flushes its buffer on each BufferingTimeout interval.
	BufferingTimeout time.Duration

	// Tag prefix. When set TagPrefix to "foo" and post with "bar.baz",
	// you'll get "foo.bar.baz" tag.
	TagPrefix string
}

Config is just for fluent.NewLogger() argument.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger owns asynchronous logging to fluentd.

func NewLogger

func NewLogger(config Config) *Logger

NewLogger() launches a goroutine to log and returns logger. Logger has a channel to interact with the goroutine.

func (*Logger) Log

func (l *Logger) Log(tag string, data interface{}) error

You can send message immediately to fluentd.

func (*Logger) Post

func (l *Logger) Post(tag string, data interface{})

You can send message to logger's goroutine via channel. This logging is executed asynchronously.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL