Re: [Log4cplus-devel] some questions about log4cplus 1.0.3
Logging Framework for C++
Brought to you by:
wilx
From: Václav H. <v.h...@sh...> - 2009-03-28 19:54:17
|
Liu Xiao wrote, On 28.3.2009 19:19: > hi,wilx Hi, please, next time use either the support tracker or the log4cplus-devel mailing list so that everybody can participate. > > thanks for reading > > I am trying to use log4cplus in some of my works, and i wrote a simple > program attached with this e-mail. > > the program is a very simple multi-threads program,just in the same way > i hope to use in my real works,but this program can't run properly under > linux. Next time also provide more information. What is that you expect? What is that you actually get? If these two differ then why do you think one is wrong and the other is right? Etc. > > In my real works,there would be a lot of different log need to be > written, all writing called from different thread in a threads-pool, and > different thread may write log to the same file. > > I have tried very hard to solve it. but still have no idea what's wrong > with it. > > Would you please tell me the right way to use log4cplus in this manner. > thanks a lot. I have commented out LogInThread2() and changed #if 0 to #if 1: int main(int argc,const char* argv[]) { #if 1 // rollingfileappender SharedAppenderPtr appender(new RollingFileAppender("./log/test.log",1024)); appender->setName("test"); // patternlayout std::string pattern = "%d{%m/%d/%y %H:%M:%S} - %m [%l]%n"; std::auto_ptr<Layout> layout(new PatternLayout(pattern)); // attach layout to appender appender->setLayout(layout); // get a logger Logger logger = Logger::getInstance("test"); // attach appender to logger logger.addAppender(appender); /// set log level logger.setLogLevel(ALL_LOG_LEVEL); //LOG4CPLUS_DEBUG(logger,"this is debug message from appender test..."); // log in other func LogToLoggerGot(); // log to size split LogToSizeSplit(); // log to thread LogInThread(); #endif // LogInThread2(); return 0; } Here, LogInThread2() will never work right. Once you exit main(), log4cplus will deinitialize and stop working. LogInThread() does it right, you have to wait for the threads to finish. In void* FuncThread(void* data), you have line: std::string path = "./log/"+ix+"/test.log"; This will not work, the appender does not create directory structure. The directory with the name in the ix variable does not exist. Changing the line like in the following example makes it log nicely into files in the log directory: std::string path = "./log/"+ix+"-test.log"; > > ps: > > version of log4cplus : 1.0.3 (log4cplus-1.0.3.tar.bz2 > <http://downloads.sourceforge.net/log4cplus/log4cplus-1.0.3.tar.bz2?use_mirror=nchc>), > also tried 1.0.2,which makes no difference. > configure called like this: ./configure > --prefix=/home/liuxiao/lib/log4cplus/ --enable-debugging --with-pic > --enable-threads=yes -- VH PS: I am adding CC to log4cplus-devel mailing list. |