Dear Gophers,
I was about to adopt “12-factor” and initially just use stdout for logging and
let rotation and redirection for the environment. But then I’m totally involved
with CGO, I have lots of goroutines and threads in the same physical process.
I even came to ask this on SO:
But then came to realize (with confirmation): Forget log synchronization, just
logically separate Go and C for logging.
It seems the least worse, but not optimal:
Do you guys have experience on this topic to provide good advice and wisdom?
Yours truly,
Francisco Lopes
I can't really speak to what the "best practice" is, but I found the simplest solution for me (and has been working fine for my purposes) is just to export my Go logging function and call that (or a wrapper around it) from C.
I had the same issue, I got around it by writing a variadic function in C which runs C's sprintf on its args and then passes the single string result to my exported Go logging function.
Ah, I misunderstood. I'm not really familiar with logfmt and was thinking you were just trying to accomplish std logging.However, might it be possible to serialize the C variadic args, pass them as a single string/value and deserialize on the Go side?To help me better understand what you're trying to accomplish, which Go library are you using for logfmt?