1、不要频繁调用Logger::get() ,而应总是调用1次,存储引用,使用引用;
You should avoid calling Logger::get() frequently. It's much better
to call it once for every logger you're going to use, and then store
the reference to the logger for later use.
2、总是检查消息是否会被输出,如果不被输出就不要构建消息。poco预定义的宏解决了这个问题。
There are also macros that do the check before constructing the
message:
poco_fatal(msg), poco_critical(msg), poco_error(msg), etc.
1: // ...
2: if (logger.warning())
3: {
4: std::string msg("This is a warning");
5: logger.warning(msg);
6: }
7: // is equivalent to
8: poco_warning(logger, "This is a warning");