mirror of https://github.com/aria2/aria2
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made string listeral to static const std::string. * src/A2STR.cc * src/A2STR.h * src/SimpleLogger.cc * src/SimpleLogger.hpull/1/head
parent
1942b8d7b3
commit
a37af74369
|
@ -1,3 +1,11 @@
|
||||||
|
2008-05-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Made string listeral to static const std::string.
|
||||||
|
* src/A2STR.cc
|
||||||
|
* src/A2STR.h
|
||||||
|
* src/SimpleLogger.cc
|
||||||
|
* src/SimpleLogger.h
|
||||||
|
|
||||||
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-05-13 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Made string literal to static const std::string.
|
Made string literal to static const std::string.
|
||||||
|
|
|
@ -40,4 +40,8 @@ const std::string A2STR::NIL("");
|
||||||
|
|
||||||
const std::string A2STR::SHARP_C("#");
|
const std::string A2STR::SHARP_C("#");
|
||||||
|
|
||||||
|
const std::string A2STR::CR_C("\r");
|
||||||
|
|
||||||
|
const std::string A2STR::LF_C("\n");
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -46,6 +46,11 @@ public:
|
||||||
static const std::string NIL;
|
static const std::string NIL;
|
||||||
|
|
||||||
static const std::string SHARP_C;
|
static const std::string SHARP_C;
|
||||||
|
|
||||||
|
static const std::string CR_C;
|
||||||
|
|
||||||
|
static const std::string LF_C;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "a2io.h"
|
#include "a2io.h"
|
||||||
#include "a2time.h"
|
#include "a2time.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
|
#include "A2STR.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -69,6 +70,16 @@ writeStackTrace(Logger::LEVEL, EX);\
|
||||||
flush();\
|
flush();\
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
|
const std::string SimpleLogger::DEBUG("DEBUG");
|
||||||
|
|
||||||
|
const std::string SimpleLogger::NOTICE("NOTICE");
|
||||||
|
|
||||||
|
const std::string SimpleLogger::WARN("WARN");
|
||||||
|
|
||||||
|
const std::string SimpleLogger::ERROR("ERROR");
|
||||||
|
|
||||||
|
const std::string SimpleLogger::INFO("INFO");
|
||||||
|
|
||||||
SimpleLogger::SimpleLogger():stdoutField(0) {}
|
SimpleLogger::SimpleLogger():stdoutField(0) {}
|
||||||
|
|
||||||
SimpleLogger::~SimpleLogger() {
|
SimpleLogger::~SimpleLogger() {
|
||||||
|
@ -112,20 +123,20 @@ void SimpleLogger::writeLog(std::ostream& o, Logger::LEVEL level,
|
||||||
std::string levelStr;
|
std::string levelStr;
|
||||||
switch(level) {
|
switch(level) {
|
||||||
case Logger::DEBUG:
|
case Logger::DEBUG:
|
||||||
levelStr = "DEBUG";
|
levelStr = DEBUG;
|
||||||
break;
|
break;
|
||||||
case Logger::NOTICE:
|
case Logger::NOTICE:
|
||||||
levelStr = "NOTICE";
|
levelStr = NOTICE;
|
||||||
break;
|
break;
|
||||||
case Logger::WARN:
|
case Logger::WARN:
|
||||||
levelStr = "WARN";
|
levelStr = WARN;
|
||||||
break;
|
break;
|
||||||
case Logger::ERROR:
|
case Logger::ERROR:
|
||||||
levelStr = "ERROR";
|
levelStr = ERROR;
|
||||||
break;
|
break;
|
||||||
case Logger::INFO:
|
case Logger::INFO:
|
||||||
default:
|
default:
|
||||||
levelStr = "INFO";
|
levelStr = INFO;
|
||||||
}
|
}
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
char datestr[20];
|
char datestr[20];
|
||||||
|
@ -139,7 +150,7 @@ void SimpleLogger::writeLog(std::ostream& o, Logger::LEVEL level,
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
char* res;
|
char* res;
|
||||||
if(vasprintf(&res, std::string(Util::replace(msg, "\r", "")+"\n").c_str(), apCopy) == -1) {
|
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";
|
o << "SimpleLogger error, cannot allocate memory.\n";
|
||||||
} else {
|
} else {
|
||||||
o << res;
|
o << res;
|
||||||
|
|
|
@ -59,6 +59,16 @@ private:
|
||||||
|
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
int stdoutField;
|
int stdoutField;
|
||||||
|
|
||||||
|
static const std::string DEBUG;
|
||||||
|
|
||||||
|
static const std::string NOTICE;
|
||||||
|
|
||||||
|
static const std::string WARN;
|
||||||
|
|
||||||
|
static const std::string ERROR;
|
||||||
|
|
||||||
|
static const std::string INFO;
|
||||||
public:
|
public:
|
||||||
SimpleLogger();
|
SimpleLogger();
|
||||||
~SimpleLogger();
|
~SimpleLogger();
|
||||||
|
|
Loading…
Reference in New Issue