@题外话,欢迎加入qq群:341974971 一起进行Poco C++的探讨吧;
1 PatternFormatter类内部有 %u 和%U ,分别代表行号和File名,没有参数的情况下默认为0和null;
2 需要搭配__FILE__ 和 __LINE__ 宏
3 使用方法:以Information 级别为例
eg:
PatternFormatter* pForm=new PatternFormatter("[%Y-%m-%d] %H:%M:%S [%U(%u)] ");
pForm->setProperty("times","local");
FileChannel* pChannel=new FileChannel();
pChannel->setProperty("path",config().getString("App.log_file")+"Log_first.log");
FormattingChannel* pFC1=new FormattingChannel(pForm,pChannel);
Logger::root().setChannel(pFC1);
Logger::root().information("helloworld666",__FILE__,__LINE__);
Logger::root().information("helloworld123");
4 结论:
__FILE__ 这个与%U所对应,输出带有路径的文件名;
__LINE__ 这个 与%u 所对应,输出 该日志的行号;
如果没有这两个宏或者没有%U和%u,则日志输出不会带有文件名和行号;