2008-05-31 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Do not do write operation to /dev/null file.
	* src/LogFactory.cc
	* src/SimpleLogger.cc

	Replaced vasprintf with vsnprintf
	* src/SimpleLogger.cc (SimpleLogger::writeLog)
pull/1/head
Tatsuhiro Tsujikawa 2008-05-31 05:56:12 +00:00
parent 405c46277f
commit 31a01bd0a6
3 changed files with 34 additions and 22 deletions

View File

@ -1,3 +1,12 @@
2008-05-31 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Do not do write operation to /dev/null file.
* src/LogFactory.cc
* src/SimpleLogger.cc
Replaced vasprintf with vsnprintf
* src/SimpleLogger.cc (SimpleLogger::writeLog)
2008-05-31 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/BtRequestMessage.cc

View File

@ -48,7 +48,11 @@ Logger::LEVEL LogFactory::_logLevel = Logger::DEBUG;
Logger* LogFactory::getInstance() {
if(logger == NULL) {
SimpleLogger* slogger = new SimpleLogger();
if(filename != DEV_NULL) {
// don't open file DEV_NULL for performance sake.
// This avoids costly unecessary message formatting and write.
slogger->openFile(filename);
}
slogger->setLogLevel(_logLevel);
if(_consoleOutput) {
slogger->setStdout(Logger::NOTICE, true);

View File

@ -56,22 +56,22 @@ namespace aria2 {
#endif
#define WRITE_LOG(LEVEL, MSG) \
if(LEVEL >= _logLevel){\
va_list ap;\
va_start(ap, MSG);\
writeFile(LEVEL, MSG, ap);\
flush();\
va_end(ap);\
}
if(LEVEL >= _logLevel && (stdoutField&LEVEL || file.is_open())) { \
va_list ap; \
va_start(ap, MSG); \
writeFile(LEVEL, MSG, ap); \
flush(); \
va_end(ap); \
}
#define WRITE_LOG_EX(LEVEL, MSG, EX) \
if(LEVEL >= _logLevel) {\
va_list ap;\
va_start(ap, EX);\
writeFile(LEVEL, MSG, ap);\
writeStackTrace(LEVEL, EX);\
flush();\
va_end(ap);\
if(LEVEL >= _logLevel && (stdoutField&LEVEL || file.is_open())) { \
va_list ap; \
va_start(ap, EX); \
writeFile(LEVEL, MSG, ap); \
writeStackTrace(LEVEL, EX); \
flush(); \
va_end(ap); \
}
const std::string SimpleLogger::DEBUG("DEBUG");
@ -153,12 +153,11 @@ void SimpleLogger::writeLog(std::ostream& o, Logger::LEVEL level,
writeHeader(o, datestr, levelStr);
}
{
char* res;
if(vasprintf(&res, std::string(Util::replace(msg, A2STR::CR_C, A2STR::NIL)+A2STR::LF_C).c_str(), apCopy) == -1) {
o << "SimpleLogger error, cannot allocate memory.\n";
char buf[1024];
if(vsnprintf(buf, sizeof(buf), std::string(Util::replace(msg, A2STR::CR_C, A2STR::NIL)+A2STR::LF_C).c_str(), apCopy) < 0) {
o << "SimpleLogger error, failed to format message.\n";
} else {
o << res;
free(res);
o << buf;
}
}
va_end(apCopy);