Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use printf format when using log4cplus?

Does log4cplus gives an API to print in C-Style / printf format?

Reason: I would like to use log4cplus in C code (in addition to C++) and don't want to prepare the string before hand.

like image 771
DavidS Avatar asked Feb 26 '26 16:02

DavidS


1 Answers

All the logging macros have an FMT variant that does what you expect:

LOG4CPLUS_WARN_FMT(logger, "Hello %s %d", "World", 1);

Compare/contrast with the "default" variant, which uses C++ streams:

LOG4CPLUS_WARN(logger, "Hello " << "World " << 1);

There's also an _STR variant which can be used to output an std::string if you have it ready (without paying for the overhead of a C++ string stream).

like image 197
Matteo Italia Avatar answered Mar 01 '26 08:03

Matteo Italia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!