26 Mutex* Logger::_theLogmutex = NULL;
27 string* Logger::level = NULL;
28 string* Logger::mode = NULL;
29 string* Logger::filepath = NULL;
31 ofstream* Logger::out = NULL;
33 string Logger::LEVEL_ERROR =
"ERROR";
34 string Logger::LEVEL_DEBUG =
"DEBUG";
35 string Logger::LEVEL_INFO =
"INFO";
37 Logger Logger::getLogger(
string className)
48 _theLogmutex =
new Mutex();
49 level =
new string(LEVEL_ERROR);
50 mode =
new string(
"CONSOLE");
51 datFormat =
new DateFormat(
"dd/mm/yyyy hh:mi:ss");
55 void Logger::init(
string file)
59 _theLogmutex =
new Mutex();
62 propMap props = pf.getProperties(file);
65 level =
new string(LEVEL_ERROR);
66 mode =
new string(
"CONSOLE");
67 datFormat =
new DateFormat(
"dd/mm/yyyy hh:mi:ss");
70 level =
new string(props[
"LEVEL"]);
71 mode =
new string(props[
"MODE"]);
72 filepath =
new string(props[
"FILEPATH"]);
77 out->open(filepath->c_str(),ios::app | ios::binary);
82 void Logger::init(
string llevel,
string lmode,
string lfilepath)
86 _theLogmutex =
new Mutex();
88 level =
new string(llevel);
89 mode =
new string(lmode);
90 filepath =
new string(lfilepath);
91 datFormat =
new DateFormat(
"dd/mm/yyyy hh:mi:ss");
95 out->open(filepath->c_str(),ios::app | ios::binary);
103 Logger::Logger(
string className)
105 this->className = className;
113 void Logger::write(
string msg,
string mod,
bool newline)
116 string te = datFormat->format(dat);
117 msg =
"[" + te +
"] ("+this->className +
") <"+mod+
"> :"+msg+(newline?
"\n":
"");
120 _theLogmutex->lock();
121 out->write(msg.c_str(),msg.length());
123 _theLogmutex->unlock();
127 _theLogmutex->lock();
128 cout << msg << flush;
129 _theLogmutex->unlock();
133 void Logger::write(ostream& (*pf) (ostream&),
string mod)
137 _theLogmutex->lock();
139 _theLogmutex->unlock();
143 _theLogmutex->lock();
145 _theLogmutex->unlock();
149 void Logger::info(
string msg)
151 if(*level!=LEVEL_DEBUG)
153 write(msg,
"info",
true);
157 void Logger::debug(
string msg)
159 if(*level==LEVEL_DEBUG)
161 write(msg,
"debug",
true);
165 void Logger::error(
string msg)
167 write(msg,
"error",
true);
170 Logger& operator<< (
Logger& logger, ostream& (*pf) (ostream&))
172 logger.write(pf,
"info");
176 void Logger::destroy()
184 if(filepath!=NULL)
delete filepath;
185 if(out!=NULL)
delete out;