r-lib / debugme

Easy and efficient debugging for R packages
https://r-lib.github.io/debugme/
Other
147 stars 10 forks source link

C/C++ API #16

Open gaborcsardi opened 7 years ago

gaborcsardi commented 7 years ago

Would be nice.

krlmlr commented 7 years ago

I use plogr for C++ logging, which has zero impact if turned off at compile time and low impact if turned off at run time.

gaborcsardi commented 7 years ago

That's not bad. But I also want it to work the same way. I.e.

krlmlr commented 7 years ago

Want to spend a couple of hours in Brussels integrating these two packages?

gaborcsardi commented 6 years ago

This would be handy for me now, but I need a solution that works in pure C code (as well). For plog, I would need to embed it into a C library, right?

krlmlr commented 6 years ago

plogr calls currently look like LOG_VERBOSE << expression;, so we'd need a whole new API for this, maybe printf-based?

gaborcsardi commented 6 years ago

Yeah, vsnprintf I guess.

gaborcsardi commented 6 years ago

And we would also need to embed the C lib into debugme or plogr...

krlmlr commented 6 years ago

plogr is header-only, can we do the same with C?

How about starting the C API in debugme, and then adapting the plogr API to use the debugme C API under the hood, or move the plogr API to debugme?

gaborcsardi commented 6 years ago

plogr is header-only, can we do the same with C?

I guess we could, but not if we use plog / plogr. I don't see how we could do it without requiring a C++ compiler. Which is bad. But FIXME.

krlmlr commented 6 years ago

I'd suggest to independently start a C header-only implementation in debugme, with env var triggers and color, and then see how to include the rather nice C++ API, but maybe without the rest of plog.

gaborcsardi commented 6 years ago

OTOH, it would be just easier to use sg like https://github.com/wonder-mice/zf_log

krlmlr commented 6 years ago

Yeah, I'd suggest to use a header-only library, though.

gaborcsardi commented 6 years ago

I am not sure if there is a header only C logging library.

krlmlr commented 6 years ago

Maybe it's sufficient if the header contains everything necessary to decide if a log event happens, and then we use R callbacks to forward to debugme?

gaborcsardi commented 6 years ago

I would avoid calling back to R if possible....

I think there is no other sensible way, but define a proper C API using R_RegisterCCallable.

krlmlr commented 6 years ago

That's what I meant ;-)

Do you agree that the logic that decides if anything is logged needs to be in the header file? How do we make this fast, ideally one memory read and one conditional jump?

gaborcsardi commented 6 years ago

Yes, sure, those must be macros.