37 #include "util/base/exception.h"
45 MODULE_INFO_RELATIONSHIPS
49 LogManager* LogManager::m_instance = NULL;
79 if (level < m_level) {
85 std::string lvlstr =
"";
87 case LEVEL_DEBUG: lvlstr =
"dbg";
90 case LEVEL_LOG: lvlstr =
"log";
93 case LEVEL_WARN: lvlstr =
"warn";
96 case LEVEL_ERROR: lvlstr =
"error";
99 case LEVEL_PANIC: lvlstr =
"panic";
102 default: lvlstr =
"error";
106 std::cout << moduleInfos[module].name <<
": " << lvlstr <<
": " << msg << std::endl;
109 *m_logfile << moduleInfos[module].name <<
": " << lvlstr <<
": " << msg << std::endl;
111 if (level == LEVEL_PANIC) {
125 validateModule(module);
126 int ind =
static_cast<int>(module);
127 m_modules[ind] =
true;
128 if (moduleInfos[ind].parent != LM_CORE) {
134 validateModule(module);
135 m_modules[module] =
false;
139 for (
int i = 0; i < LM_MODULE_MAX; i++) {
140 m_modules[i] =
false;
145 m_logtoprompt = log_to_promt;
149 return m_logtoprompt;
154 m_logfile =
new std::ofstream(
"fife.log");
161 m_logtofile = logtofile;
169 if (!m_modules[module]) {
172 if (moduleInfos[module].parent != LM_CORE) {
173 return isVisible(moduleInfos[module].parent);
178 LogManager::LogManager():
179 m_level(LEVEL_DEBUG),
180 module_check_stack(),
182 m_logtoprompt(false) {
183 validateModuleDescription(LM_CORE);
188 void LogManager::validateModule(logmodule_t m) {
189 if ((m <= LM_CORE) || (m >= LM_MODULE_MAX)) {
190 std::cout <<
"Invalid module received in LogManager: " << m <<
", aborting\n";
195 void LogManager::validateModuleDescription(logmodule_t module) {
196 if (module == LM_CORE) {
197 for (
int m = static_cast<int>(LM_CORE)+1; m < static_cast<int>(LM_MODULE_MAX); m++) {
198 if (moduleInfos[m].module != static_cast<logmodule_t>(m)) {
199 std::ostringstream stream;
201 std::string msg =
"Log module definition ids do not match in index ";
203 std::cout << msg << std::endl;
204 throw InvalidFormat(msg);
206 module_check_stack.clear();
207 validateModuleDescription(static_cast<logmodule_t>(m));
210 module_check_stack.push_back(module);
211 if (count(module_check_stack.begin(), module_check_stack.end(), module) > 1) {
212 throw InvalidFormat(
"Log module definition hierachy contains cycles");
218 return moduleInfos[module].name;