36 #include "util/base/exception.h"
44 MODULE_INFO_RELATIONSHIPS
48 LogManager* LogManager::m_instance = NULL;
78 if (level < m_level) {
84 std::string lvlstr =
"";
86 case LEVEL_DEBUG: lvlstr =
"DEBUG";
89 case LEVEL_LOG: lvlstr =
"LOG";
92 case LEVEL_WARN: lvlstr =
"WARN";
95 case LEVEL_ERROR: lvlstr =
"ERROR";
98 case LEVEL_PANIC: lvlstr =
"PANIC";
101 default: lvlstr =
"ERROR";
105 std::cout << moduleInfos[module].name <<
":" << lvlstr <<
":" << msg << std::endl;
108 *m_logfile << moduleInfos[module].name <<
":" << lvlstr <<
":" << msg << std::endl;
110 if (level == LEVEL_PANIC) {
124 validateModule(module);
125 int32_t ind =
static_cast<int32_t
>(module);
126 m_modules[ind] =
true;
127 if (moduleInfos[ind].parent != LM_CORE) {
133 validateModule(module);
134 m_modules[module] =
false;
138 for (int32_t i = 0; i < LM_MODULE_MAX; i++) {
139 m_modules[i] =
false;
144 m_logtoprompt = log_to_promt;
148 return m_logtoprompt;
153 m_logfile =
new std::ofstream(
"fife.log");
160 m_logtofile = logtofile;
168 if (!m_modules[module]) {
171 if (moduleInfos[module].parent != LM_CORE) {
172 return isVisible(moduleInfos[module].parent);
177 LogManager::LogManager():
178 m_level(LEVEL_DEBUG),
179 module_check_stack(),
181 m_logtoprompt(false) {
182 validateModuleDescription(LM_CORE);
187 void LogManager::validateModule(logmodule_t m) {
188 if ((m <= LM_CORE) || (m >= LM_MODULE_MAX)) {
189 std::cout <<
"Invalid module received in LogManager: " << m <<
", aborting\n";
194 void LogManager::validateModuleDescription(logmodule_t module) {
195 if (module == LM_CORE) {
196 for (int32_t m = static_cast<int32_t>(LM_CORE)+1; m < static_cast<int32_t>(LM_MODULE_MAX); m++) {
197 if (moduleInfos[m].module != static_cast<logmodule_t>(m)) {
198 std::ostringstream stream;
200 std::string msg =
"Log module definition ids do not match in index ";
202 std::cout << msg << std::endl;
203 throw InvalidFormat(msg);
205 module_check_stack.clear();
206 validateModuleDescription(static_cast<logmodule_t>(m));
209 module_check_stack.push_back(module);
210 if (count(module_check_stack.begin(), module_check_stack.end(), module) > 1) {
211 throw InvalidFormat(
"Log module definition hierarchy contains cycles");
217 return moduleInfos[module].name;
void setLogToFile(bool logtofile)
void log(LogManager::LogLevel level, const std::string &msg)
void clearVisibleModules()
void addVisibleModule(logmodule_t module)
void setLogToPrompt(bool log_to_promt)
void log(LogLevel level, logmodule_t module, const std::string &msg)
LogLevel getLevelFilter()
bool isVisible(logmodule_t module)
static LogManager * instance()
void removeVisibleModule(logmodule_t module)
Logger(logmodule_t module)
std::string getModuleName(logmodule_t module)
void setLevelFilter(LogLevel level)
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...