summaryrefslogtreecommitdiff
path: root/src/SimpleLogger.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-02-22 16:01:54 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-02-22 16:01:54 +0000
commit44beebd257b0fb265bea5387850b9beb33c0adc2 (patch)
tree0ec08e4aad18ccff2d578aca1c0b3799d2716c6c /src/SimpleLogger.cc
parentd027ca8e7c383e9755d6fb997e8a880df99e88b9 (diff)
parent87a229cab18679042beb06076e5dec1dcfadaeae (diff)
Tagging release 0.2.0 of aria2release-0.2.0
Diffstat (limited to 'src/SimpleLogger.cc')
-rw-r--r--src/SimpleLogger.cc25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/SimpleLogger.cc b/src/SimpleLogger.cc
index 9c2b28fe..efb95374 100644
--- a/src/SimpleLogger.cc
+++ b/src/SimpleLogger.cc
@@ -20,6 +20,8 @@
*/
/* copyright --> */
#include "SimpleLogger.h"
+#include "Util.h"
+#include <time.h>
#include <stdarg.h>
SimpleLogger::SimpleLogger(string filename) {
@@ -36,7 +38,8 @@ SimpleLogger::~SimpleLogger() {
}
}
-void SimpleLogger::writeLog(int level, string msg, va_list ap, Exception* e) {
+void SimpleLogger::writeLog(int level, string msg, va_list ap, Exception* e) const
+{
string levelStr;
switch(level) {
case DEBUG:
@@ -49,21 +52,25 @@ void SimpleLogger::writeLog(int level, string msg, va_list ap, Exception* e) {
default:
levelStr = "INFO";
}
- vfprintf(file, string(levelStr+" - "+msg+"\n").c_str(), ap);
+ time_t now = time(NULL);
+ char datestr[26];
+ ctime_r(&now, datestr);
+ datestr[strlen(datestr)-1] = '\0';
+ vfprintf(file, string(string(datestr)+" - "+levelStr+" - "+Util::replace(msg, "\r", "")+"\n").c_str(), ap);
if(e != NULL) {
- fprintf(file, string(levelStr+" - exception: "+e->getMsg()+"\n").c_str());
+ fprintf(file, string(string(datestr)+" - "+levelStr+" - exception: "+Util::replace(e->getMsg(), "\r", "")+"\n").c_str());
}
fflush(stdout);
}
-void SimpleLogger::debug(string msg, ...) {
+void SimpleLogger::debug(string msg, ...) const {
va_list ap;
va_start(ap, msg);
writeLog(DEBUG, msg, ap);
va_end(ap);
}
-void SimpleLogger::debug(string msg, Exception* e, ...) {
+void SimpleLogger::debug(string msg, Exception* e, ...) const {
va_list ap;
va_start(ap, e);
writeLog(DEBUG, msg, ap, e);
@@ -71,14 +78,14 @@ void SimpleLogger::debug(string msg, Exception* e, ...) {
}
-void SimpleLogger::info(string msg, ...) {
+void SimpleLogger::info(string msg, ...) const {
va_list ap;
va_start(ap, msg);
writeLog(INFO, msg, ap);
va_end(ap);
}
-void SimpleLogger::info(string msg, Exception* e, ...) {
+void SimpleLogger::info(string msg, Exception* e, ...) const {
va_list ap;
va_start(ap, e);
writeLog(INFO, msg, ap, e);
@@ -86,14 +93,14 @@ void SimpleLogger::info(string msg, Exception* e, ...) {
}
-void SimpleLogger::error(string msg, ...) {
+void SimpleLogger::error(string msg, ...) const {
va_list ap;
va_start(ap, msg);
writeLog(ERROR, msg, ap);
va_end(ap);
}
-void SimpleLogger::error(string msg, Exception* e, ...) {
+void SimpleLogger::error(string msg, Exception* e, ...) const {
va_list ap;
va_start(ap, e);
writeLog(ERROR, msg, ap, e);