From: slack Date: Wed, 13 May 2009 18:22:45 +0000 (+0200) Subject: fixed logging to a file X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=211ab4e93b2dab3a9f6a3809d13718aab9887f16;p=wenboi.git fixed logging to a file --- diff --git a/common/Logger.h b/common/Logger.h index d2857aa..cff9611 100644 --- a/common/Logger.h +++ b/common/Logger.h @@ -39,18 +39,20 @@ class Logger: public Singleton }; Logger(): - out(std::ofstream("wenboi.log")), + out(new std::ofstream("wenboi.log")), current_log_level(WARNING), log_start_time(time(NULL)) { //log_start_time = time(NULL); - out << "Starting log at " << static_cast(log_start_time) << std::endl; + (*out) << "Starting log at " << static_cast(log_start_time) << std::endl; } + ~Logger() { delete out; } + void log(log_level level, std::string str) { if (level <= current_log_level) - out << "[" << difftime(time(NULL), log_start_time) << "] " << str << std::endl; + (*out) << "[" << difftime(time(NULL), log_start_time) << "] " << str << std::endl; } #define LOGFUNC1(func, tag) template void func(T1 p1) \ @@ -103,7 +105,7 @@ class Logger: public Singleton void set_log_level (log_level level) { current_log_level = level; } private: - std::ostream &out; + std::ostream *out; log_level current_log_level; time_t log_start_time; };