debugme icon indicating copy to clipboard operation
debugme copied to clipboard

C/C++ API

Open gaborcsardi opened this issue 8 years ago • 17 comments

Would be nice.

gaborcsardi avatar Jun 12 '17 11:06 gaborcsardi

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.

krlmlr avatar Jun 13 '17 09:06 krlmlr

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

  • turning on/off using the DEBUGME environment variable
  • printing messages in color

gaborcsardi avatar Jun 13 '17 09:06 gaborcsardi

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

krlmlr avatar Jun 13 '17 09:06 krlmlr

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?

gaborcsardi avatar Dec 03 '17 14:12 gaborcsardi

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

krlmlr avatar Dec 03 '17 14:12 krlmlr

Yeah, vsnprintf I guess.

gaborcsardi avatar Dec 03 '17 14:12 gaborcsardi

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

gaborcsardi avatar Dec 03 '17 14:12 gaborcsardi

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?

krlmlr avatar Dec 03 '17 14:12 krlmlr

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.

gaborcsardi avatar Dec 03 '17 14:12 gaborcsardi

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.

krlmlr avatar Dec 03 '17 14:12 krlmlr

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

gaborcsardi avatar Dec 03 '17 15:12 gaborcsardi

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

krlmlr avatar Dec 03 '17 16:12 krlmlr

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

gaborcsardi avatar Dec 03 '17 19:12 gaborcsardi

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?

krlmlr avatar Dec 03 '17 19:12 krlmlr

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.

gaborcsardi avatar Dec 03 '17 19:12 gaborcsardi

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?

krlmlr avatar Dec 03 '17 19:12 krlmlr

Yes, sure, those must be macros.

gaborcsardi avatar Dec 03 '17 19:12 gaborcsardi