fluent-bit-go icon indicating copy to clipboard operation
fluent-bit-go copied to clipboard

Access to logger

Open majst01 opened this issue 8 years ago • 7 comments

I implemented a redis output plugin: https://github.com/majst01/fluent-bit-go-redis-output and i want to log errors during configuration parsing or processing. Currently i do this with a simple fmt.Printf(). This is not perfect as this will come out on stdout instead of the configured log destination. It also does look different than other existing log entries and there is not destinction between info/debug/error etc.

I have already seen in flb_log.h there are already handy macros defined:

/* Logging macros */
#define flb_error(fmt, ...)                                          \
    if (flb_log_check(FLB_LOG_ERROR))                                \
        flb_log_print(FLB_LOG_ERROR, NULL, 0, fmt, ##__VA_ARGS__)

#define flb_warn(fmt, ...)                                           \
    if (flb_log_check(FLB_LOG_WARN))                                 \
        flb_log_print(FLB_LOG_WARN, NULL, 0, fmt, ##__VA_ARGS__)

#define flb_info(fmt, ...)                                           \
    if (flb_log_check(FLB_LOG_INFO))                                 \
        flb_log_print(FLB_LOG_INFO, NULL, 0, fmt, ##__VA_ARGS__)

but the current implementation of fluent-bit-go does not expose them to to golang interface. Can someone give hints howto start, im willing to implement this or help someone to do so.

Greetings and congrats to this simple but working api !

majst01 avatar Nov 28 '17 17:11 majst01

This sounds like a good idea. It would extend the ABI between fluent-bit and the plugin .so to share a pointer to this function. Perhaps this could be added to struct flb_api since that is already a container for function pointers that point back to functions implemented in fluent-bit:

https://github.com/fluent/fluent-bit-go/blob/51032bd05190bd178085a56c410706696fbd3177/output/flb_output.h#L25-L27

jasonkeene avatar Apr 17 '19 17:04 jasonkeene

This is a bit of a stale issue but if you are still interested in working on this I would be willing to help. Just ping me on the fluent slack.

jasonkeene avatar Apr 17 '19 17:04 jasonkeene

Hi,

still interested, gimmi some time to join

majst01 avatar Apr 17 '19 19:04 majst01

done

majst01 avatar Apr 20 '19 07:04 majst01

FYI: this is a must, feel free to send the PR

edsiper avatar Apr 21 '19 04:04 edsiper

Cgo does not support calling variadic C functions, so we could only implement a wrapper for flb_error("%s", x);, etc.

https://golang.org/cmd/cgo/

l2dy avatar Oct 28 '19 11:10 l2dy

Hi, I'd like to work on this, but being a total Go beginner, I'm having a hard time to start. Precisely, I can't understand how to edit a 3rd party package in general.

I forked this repo and then tried to import it by changing the import url, go mod tidy, go get <my_url>

But i keep getting

go: downloading github.com/brisa-robotics/fluent-bit-go v0.0.0-20221204101412-4d1575bac6fe
go: github.com/brisa-robotics/[email protected]: parsing go.mod:
	module declares its path as: github.com/fluent/fluent-bit-go
	        but was required as: github.com/brisa-robotics/fluent-bit-go

Is there a way to a local directory otherwise? Thanks

Minipada avatar Dec 04 '22 10:12 Minipada