fluent-logger-go: github.com/daichirata/fluent-logger-go Index | Examples | Files

package fluent

import "github.com/daichirata/fluent-logger-go"

Index

Examples

Package Files

buffer.go error_handler.go logger.go message.go

type Config Uses

type Config struct {
    Address           string
    ConnectionTimeout time.Duration
    FailureThreshold  int64
    FlushInterval     time.Duration
    PendingLimit      int
}

type ErrorHandler Uses

type ErrorHandler interface {
    HandleError(error, []byte) error
}

type ErrorHandlerFunc Uses

type ErrorHandlerFunc func(error, []byte) error

func (ErrorHandlerFunc) HandleError Uses

func (f ErrorHandlerFunc) HandleError(err error, data []byte) error

type FallbackHandler Uses

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

func NewFallbackHandler Uses

func NewFallbackHandler(logger *Logger) *FallbackHandler

func (*FallbackHandler) HandleError Uses

func (h *FallbackHandler) HandleError(_ error, data []byte) error

type FallbackJSONHandler Uses

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

func NewFallbackJSONHandler Uses

func NewFallbackJSONHandler(io io.Writer) *FallbackJSONHandler

func (*FallbackJSONHandler) HandleError Uses

func (h *FallbackJSONHandler) HandleError(_ error, data []byte) error

type Logger Uses

type Logger struct {
    // ErrorHandler handle error events. If Errorhandler is set, it is called
    // with error and message which failed to send as arguments.
    // If ErrorHandler does not return error, it means that the sending of the
    // message was successful.
    ErrorHandler ErrorHandler
    // contains filtered or unexported fields
}

func NewLogger Uses

func NewLogger(c Config) (*Logger, error)

NewLogger generates a new Logger instance.

Code:

_, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}
// See the other examples to learn how to use the Logger.

Code:

logger, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}

// Logging error.
logger.ErrorHandler = fluent.ErrorHandlerFunc(func(err error, _ []byte) error {
    log.Println(err)
    return err
})

// Fallback logger.
fallback, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}
logger.ErrorHandler = fluent.NewFallbackHandler(fallback)

func (*Logger) Close Uses

func (logger *Logger) Close() error

Close will block until all messages has been sent.

Code:

logger, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}

for i := 0; i < 10; i++ {
    err = logger.Post("tag-name", map[string]string{
        "foo": "bar",
    })
    if err != nil {
        // TODO: Handle error.
    }
}

// Close will block until all messages has been sent.
err = logger.Close()
if err != nil {
    // TODO: Handle error.
}

func (*Logger) Post Uses

func (logger *Logger) Post(tag string, obj interface{}) error

Post a message to fluentd. This method returns an error if encoding to msgpack fails. Message posting processing is performed asynchronously by goroutine, so it will not block.

Code:

logger, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}

err = logger.Post("tag-name", map[string]string{
    "foo": "bar",
})
if err != nil {
    // TODO: Handle error.
}

Code:

logger, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}

data := struct {
    Foo string `msgpack:"foo"`
    Bar string `msgpack:"bar"`
}{
    Foo: "foo",
    Bar: "bar",
}
err = logger.Post("tag-name", data)
if err != nil {
    // TODO: Handle error.
}

func (*Logger) PostWithTime Uses

func (logger *Logger) PostWithTime(tag string, t time.Time, obj interface{}) error

PostWithTime posts a message with specified time to fluentd.

Code:

logger, err := fluent.NewLogger(fluent.Config{})
if err != nil {
    // TODO: Handle error.
}

data := struct {
    Foo string `msgpack:"foo"`
    Bar string `msgpack:"bar"`
}{
    Foo: "foo",
    Bar: "bar",
}
// Post a message with specified time
err = logger.PostWithTime("tag-name", time.Now().Add(-5*time.Second), data)
if err != nil {
    // TODO: Handle error.
}

func (*Logger) Subscribe Uses

func (logger *Logger) Subscribe() <-chan circuit.BreakerEvent

Subscribe returns a channel of circuit.BreakerEvents.

type Message Uses

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

Package fluent imports 10 packages (graph). Updated 2018-01-09. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).