RCF support and general discussion.
acDev
Posts: 27 Joined: Tue Oct 08, 2013 3:08 pm
Location: Moscow
Contact:
Post
by acDev » Sat Nov 23, 2013 7:42 am
Logging to StdOut only:
Code: Select all
#define MYLOGFMT "%C (%D) %X"
#define MYLOGNAME 8
#define RCFLOG3() UTIL_LOG(MYLOGNAME, RCF::LogLevel_3) << "[MyLog] "
std::string myLogFormat = MYLOGFMT;
RCF::enableLogging(RCF::LogToStdout(), 3, myLogFormat);
RCF::LoggerPtr myLogPtr(new RCF::Logger(MYLOGNAME, 3, RCF::LogToStdout(), myLogFormat));
myLogPtr->activate();
RCFLOG3() << "Server started!";
It's work fine.
Logging to File only:
Code: Select all
#define MYLOGFMT "%C (%D) %X"
#define MYLOGNAME 8
#define RCFLOG3() UTIL_LOG(MYLOGNAME, RCF::LogLevel_3) << "[MyLog] "
std::string myLogFormat = MYLOGFMT;
RCF::enableLogging(RCF::LogToFile("srv.log"), 3, myLogFormat);
RCF::LoggerPtr myLogPtr(new RCF::Logger(MYLOGNAME, 3, RCF::LogToFile("srv.log"), myLogFormat));
myLogPtr->activate();
RCFLOG3() << "Server started!";
String
"Server started!" not logged!
How logging to StdOut and File together?
jarl
Posts: 238 Joined: Mon Oct 03, 2011 4:53 am
Contact:
Post
by jarl » Wed Nov 27, 2013 2:43 am
The reason the string isn't appearing in the file is because it is being buffered... There is an extra parameter in the LogToFile constructor, which you can set to true, to force a flush after each logging call :
Code: Select all
RCF::LoggerPtr log2Ptr(new RCF::Logger(MYLOGNAME, 3, RCF::LogToFile("srv.log", true), myLogFormat));
The following code will get your log statements appearing both in the file and on stdout:
Code: Select all
#define MYLOGFMT "%C (%D) %X"
#define MYLOGNAME 8
#define RCFLOG3() UTIL_LOG(MYLOGNAME, RCF::LogLevel_3) << "[MyLog] "
RCF::LoggerPtr log1Ptr(new RCF::Logger(MYLOGNAME, 3, RCF::LogToStdout(), myLogFormat));
log1Ptr->activate();
RCF::LoggerPtr log2Ptr(new RCF::Logger(MYLOGNAME, 3, RCF::LogToFile("srv.log", true), myLogFormat));
log2Ptr->activate();
RCFLOG3() << "Server started!";