fix NULL pointer access on ~Area
[Tsunagari.git] / src / log.cpp
blobbf1829484be15f2ec452c70e2004f88f6fd6f72b
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** log.cpp **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include "config.h"
8 #include "log.h"
10 /**
11 * Singleton enforcement.
13 Log* Log::instance()
15 static Log* inst = NULL;
16 if (!inst) {
17 inst = new Log;
20 return inst;
23 Log::Log()
25 mode = MESSAGE_MODE;
28 /**
29 * Specify mode setting.
31 void Log::setMode(message_mode_t mode)
33 Log* l = instance();
34 l->mode = mode;
37 /**
38 * Give output to the "write" function if it is allowed to be sent in
39 * the current mode.
41 void Log::err(std::string domain, std::string message)
43 std::cerr << "Error [" << domain << "] - " << rtrim(message)
44 << std::endl;
47 void Log::dev(std::string domain, std::string message)
49 Log* l = instance();
50 if (l->mode == MM_DEBUG || l->mode == MM_DEVELOPER)
51 std::cerr << "Devel [" << domain << "] - " << rtrim(message)
52 << std::endl;
55 void Log::dbg(std::string domain, std::string message)
57 Log* l = instance();
58 if (l->mode == MM_DEBUG)
59 std::cerr << "Debug [" << domain << "] - " << rtrim(message)
60 << std::endl;
63 std::string& Log::rtrim(std::string& str)
65 if (str[str.length()-1] == '\n')
66 str[str.length()-1] = '\0';
67 return str;