package fluentd import ( "fmt" "log" "github.com/fluent/fluent-logger-golang/fluent" ) type Logger struct { fluent *fluent.Fluent appName string } func NewLogger(appName, fHost string, fPort int) *Logger { config := fluent.Config{ FluentHost: fHost, FluentPort: fPort, // WriteTimeout: -1, } fluent, err := fluent.New(config) if err != nil { log.Panicf("Error connecting to %s: %v", fHost, err) } return &Logger{fluent, appName} } func (l *Logger) Log(format string, v ...any) { mapData := map[string]string{ "message": fmt.Sprintf(format, v...), } err := l.fluent.Post(l.appName, mapData) if err != nil { log.Println("Error sending log: ", err) } } func (l *Logger) Close() error { return l.fluent.Close() }