Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example does not work when using "async or asyncConnect" options #129

Open
mgazza opened this issue Oct 11, 2024 · 0 comments
Open

example does not work when using "async or asyncConnect" options #129

mgazza opened this issue Oct 11, 2024 · 0 comments

Comments

@mgazza
Copy link

mgazza commented Oct 11, 2024

When using the example with fluentd listening locally if you add Async or Async connect the message "Unable to send logs to fluentd, reconnecting..." is printed out but an strace shows that no connection is ever made.

package main

import (
	"fmt"
	"log"
	"time"

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

func main() {
	logger, err := fluent.New(fluent.Config{FluentPort: 24224, FluentHost: "127.0.0.1", Async: true,
			MaxRetry:     -1,
		})
	if err != nil {
		fmt.Println(err)
	}
	defer logger.Close()
	tag := "myapp.access"
	var data = map[string]string{
		"foo":  "bar",
		"hoge": "hoge"}
	for i := 0; i < 100; i++ {
		e := logger.Post(tag, data)
		if e != nil {
			log.Println("Error while posting log: ", e)
		} else {
			log.Println("Success to post log")
		}
		time.Sleep(1000 * time.Millisecond)
	}
}

## Output without async options

2024/10/11 12:35:31 Success to post log
2024/10/11 12:35:32 Success to post log
2024/10/11 12:35:33 Success to post log
2024/10/11 12:35:34 Success to post log
2024/10/11 12:35:35 Success to post log


## Output with asyncConnect

fluent#New: AsyncConnect is now deprecated, please use Async instead2024/10/11 12:37:20 Success to post log
[2024-10-11T12:37:20Z] Unable to send logs to fluentd, reconnecting...
2024/10/11 12:37:21 Success to post log
[2024-10-11T12:37:21Z] Unable to send logs to fluentd, reconnecting...
2024/10/11 12:37:22 Success to post log
[2024-10-11T12:37:22Z] Unable to send logs to fluentd, reconnecting...
2024/10/11 12:37:23 Success to post log
[2024-10-11T12:37:23Z] Unable to send logs to fluentd, reconnecting...


## Output as per the code sample

2024/10/11 12:37:53 Success to post log
[2024-10-11T12:37:53Z] Unable to send logs to fluentd, reconnecting...
2024/10/11 12:37:54 Success to post log
[2024-10-11T12:37:54Z] Unable to send logs to fluentd, reconnecting...
2024/10/11 12:37:55 Success to post log
[2024-10-11T12:37:55Z] Unable to send logs to fluentd, reconnecting...
2024/10/11 12:37:56 Success to post log
[2024-10-11T12:37:56Z] Unable to send logs to fluentd, reconnecting...


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant