LoggingConfigurator + AsyncChannel

A general discussion forum.
cdelmas
Posts: 46
Joined: 22 Sep 2006, 10:04
Location: France

LoggingConfigurator + AsyncChannel

Postby cdelmas » 22 Mar 2007, 14:19

I have some trouble using LoggingConfigurator with AsyncChannel.

I successfully create a logger with an AsyncChannel (pointing on a file), but the logged messages never reach the file. In fact, all the messages are in the notification queue, and are discarded during the destruction of the object. Indeed, the thread is never launched !
Am I missing something, as this works when creating the logger manually ?

This is the conf file :
^logging.formatters.format2.class = PatternFormatter

logging.formatters.format2.pattern = **************

logging.formatters.format2.times = local


logging.channels.file2.class = FileChannel

logging.channels.file2.formatter = format2

logging.channels.file2.path = C:\tmp\logmethreads.log

logging.channels.file2.rotation = 1 hours

logging.channels.file2.purgeAge = 3 hours

logging.channels.file2.times = local

logging.channels.file2.compress = true


logging.channels.asyncFile.class = AsyncChannel

logging.channels.asyncFile.channel = file2

logging.loggers.thread.channel = asyncFile

logging.loggers.thread.name = thread^

And this is the code :

Code: Select all


void init() {
   LoggingConfigurator configurator;
   AutoPtr conf = new PropertyFileConfiguration("C:\tmp\logger.conf");
   configurator.configure(conf);
}

void iterminate() {
   Logger::shutdown();
}

class Dummy : public Runnable {
public:
   Dummy(int id):_id(id){}

   void run() {
      stringstream stream;
      stream << "Call from thread n°" << _id << ".";
      string msg(stream.str());
      for(unsigned int i = 0;i< 10;++i) {
         Logger& logger = Logger::get("thread");
         logger.notice(msg);
      }
   }
private:
   int _id;
};

int main(int argc, char** argv) {
   init();
   Thread t1,t2,t3;
   Dummy e1(1), e2(2), e3(3);
   t1.start(e1);
   t2.start(e2);
   t3.start(e3);
   t1.join();
   t2.join();
   t3.join();
   iterminate();
}

guenter
Posts: 1183
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: LoggingConfigurator + AsyncChannel

Postby guenter » 22 Mar 2007, 14:45

It seems that in your program the AsyncChannel gets destroyed before it has any chance to do its work. Try putting a

Code: Select all


Thread::sleep(1000)

before iterminate() and see if it works then.


cdelmas
Posts: 46
Joined: 22 Sep 2006, 10:04
Location: France

Re: Re: LoggingConfigurator + AsyncChannel

Postby cdelmas » 22 Mar 2007, 15:09

I tried

Code: Select all


Thread::sleep(10000);

but the result is the same. I put breakpoints in all functions of NotificationQueue, and no function other than clear and enqueueNotification is called. Another really strange thing : AsyncChannel::open is never called !

guenter
Posts: 1183
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Re: Re: LoggingConfigurator + AsyncChannel

Postby guenter » 23 Mar 2007, 08:57

Please try the following:

in AsyncChannel.cpp, replace AsyncChannel::open() with

Code: Select all


void AsyncChannel::open()
{
   FastMutex::ScopedLock lock(_mutex);

   if (!_thread.isRunning())
      _thread.start(*this);
}


and AsyncChannel::log() with

Code: Select all


void AsyncChannel::log(const Message& msg)
{
   open();

   _queue.enqueueNotification(new MessageNotification(msg));
}


cdelmas
Posts: 46
Joined: 22 Sep 2006, 10:04
Location: France

Re: Re: Re: Re: LoggingConfigurator + AsyncChannel

Postby cdelmas » 23 Mar 2007, 11:52

That works well ! (:mrgreen:)


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest