c – Poco :: Logger线程是否安全?

在我的测试代码中看起来像线程安全.我可以在多线程程序中使用Poco :: Logger吗?
static Poco::Logger *pLogger;    
class MyRunnable : public Poco::Runnable {
   private:
      std::string _name;
      Poco::Random _rnd;
   public:
      void setName(std::string name) {
            _name = name;
         }
      void run() {
         for (int i=0; i<200; i++) {
            pLogger->information("info from: " + _name);
            _rnd.seed(_rnd.next(65532) * _name.size());
            Poco::Thread::sleep(_rnd.next(13) + 1);
         }
      }
};

这里是测试主要:

int
main ( int argc,char *argv[] )
{
   Poco::Thread thr1,thr2,thr3;
   MyRunnable *pMyR1 = new MyRunnable(),*pMyR2 = new MyRunnable(),*pMyR3 = new MyRunnable();
   pMyR1->setName("r1");
   pMyR2->setName("ra2");
   pMyR3->setName("runable3");

   Poco::FormattingChannel *pFCFile = new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%s.%c %N[%P]:%s: %q:%t"));
   pFCFile->setChannel(new Poco::FileChannel("test.log"));
   pFCFile->open();
   pLogger = &(Poco::Logger::create("FileLogger",pFCFile,Poco::Message::PRIO_informatION));


   thr1.start(*pMyR1);
   thr2.start(*pMyR2);
   thr3.start(*pMyR3);

   std::cout << "starting..." << std::endl;
   thr1.join();
   thr2.join();
   thr3.join();
   std::cout << "end." << std::endl;
   return EXIT_SUCCESS;
}           /* ----------  end of function main  ---------- */

解决方法

这个问题很老了,但我有同样的疑问,所以在图书馆论坛上找到我发现:
http://pocoproject.org/forum/viewtopic.php?f=12&t=1233&p=2681&hilit=logger#p2681 重要的引用是:“Logger对于不同的日志记录功能是线程安全的.如果你尝试更改连接到Logger的Channel而另一个线程当前正在使用Logger,这可能会导致问题.”

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...