polish Log
[Tsunagari.git] / src / log.cpp
blob70bc027a0e24f82e8e43caa28936bbfa48b6a19a
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** log.cpp **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include "config.h"
8 #include "log.h"
10 //! Singleton enforcement.
11 Log* Log::instance()
13 static Log* inst = new Log;
14 return inst;
17 Log::Log()
19 mode = MESSAGE_MODE;
22 //! Specify mode setting.
23 void Log::setMode(message_mode_t mode)
25 Log* l = instance();
26 l->mode = mode;
30 * Give output to the "write" function if it is allowed to be sent in
31 * the current mode.
33 void Log::err(std::string domain, std::string message)
35 std::cerr << "Error [" << domain << "] - " << rtrim(message)
36 << std::endl;
39 void Log::dev(std::string domain, std::string message)
41 Log* l = instance();
42 if (l->mode == MM_DEBUG || l->mode == MM_DEVELOPER)
43 std::cerr << "Devel [" << domain << "] - " << rtrim(message)
44 << std::endl;
47 void Log::dbg(std::string domain, std::string message)
49 Log* l = instance();
50 if (l->mode == MM_DEBUG)
51 std::cerr << "Debug [" << domain << "] - " << rtrim(message)
52 << std::endl;
55 void Log::blank()
57 std::cerr << std::endl;
60 std::string& Log::rtrim(std::string& str)
62 if (str[str.length()-1] == '\n')
63 str[str.length()-1] = '\0';
64 return str;