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;
AutoPtrconf = 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();
}





