18 #include <ndb_global.h>
22 #include <LogHandler.hpp>
23 #include <ConsoleLogHandler.hpp>
24 #include <FileLogHandler.hpp>
25 #include "LogHandlerList.hpp"
28 #include "EventLogHandler.hpp"
30 #include <SysLogHandler.hpp>
43 m_pCategory(
"Logger"),
44 m_pConsoleHandler(NULL),
46 m_pSyslogHandler(NULL)
49 m_mutex= NdbMutex_Create();
50 m_handler_mutex= NdbMutex_Create();
59 delete m_pHandlerList;
60 NdbMutex_Destroy(m_handler_mutex);
61 NdbMutex_Destroy(m_mutex);
68 m_pCategory = pCategory;
74 Guard g(m_handler_mutex);
76 if (m_pConsoleHandler)
89 m_pConsoleHandler = log_handler;
96 Guard g(m_handler_mutex);
99 m_pConsoleHandler = NULL;
107 Guard g(m_handler_mutex);
128 Guard g(m_handler_mutex);
134 :
new FileLogHandler();
144 m_pFileHandler = log_handler;
151 Guard g(m_handler_mutex);
154 m_pFileHandler = NULL;
164 Guard g(m_handler_mutex);
166 if (m_pSyslogHandler)
179 m_pSyslogHandler = log_handler;
187 Guard g(m_handler_mutex);
190 m_pSyslogHandler = NULL;
198 assert(pHandler != NULL);
207 if (!m_pHandlerList->
add(pHandler))
217 DBUG_ENTER(
"Logger::addHandler");
219 logstring.
split(logdest,
";");
221 for(i = 0; i < logdest.size(); i++) {
222 DBUG_PRINT(
"info",(
"adding: %s",logdest[i].c_str()));
225 logdest[
i].split(v_type_args,
":", 2);
229 if(v_type_args.size() >= 2)
230 params = v_type_args[1];
242 else if(type ==
"CONSOLE")
278 if (pHandler != NULL)
280 if (pHandler == m_pConsoleHandler)
281 m_pConsoleHandler= NULL;
282 if (pHandler == m_pFileHandler)
283 m_pFileHandler= NULL;
284 if (pHandler == m_pSyslogHandler)
285 m_pSyslogHandler= NULL;
287 rc = m_pHandlerList->
remove(pHandler);
299 m_pConsoleHandler= NULL;
300 m_pFileHandler= NULL;
301 m_pSyslogHandler= NULL;
308 if (logLevel == LL_ALL)
310 for (
unsigned i = 1;
i < MAX_LOG_LEVELS;
i++)
315 return m_logLevels[logLevel];
322 if (logLevel == LL_ALL)
324 for (
unsigned i = 0;
i < MAX_LOG_LEVELS;
i++)
326 m_logLevels[
i] =
true;
331 m_logLevels[logLevel] =
true;
339 if (fromLogLevel > toLogLevel)
342 toLogLevel = fromLogLevel;
346 for (
int i = fromLogLevel;
i <= toLogLevel;
i++)
348 m_logLevels[
i] =
true;
356 if (logLevel == LL_ALL)
358 for (
unsigned i = 0;
i < MAX_LOG_LEVELS;
i++)
360 m_logLevels[
i] =
false;
365 m_logLevels[logLevel] =
false;
374 log(LL_ALERT, pMsg, ap);
383 log(LL_CRITICAL, pMsg, ap);
391 log(LL_ERROR, pMsg, ap);
399 log(LL_WARNING, pMsg, ap);
408 log(LL_INFO, pMsg, ap);
417 log(LL_DEBUG, pMsg, ap);
422 Logger::log(LoggerLevel logLevel,
const char* pMsg, va_list ap)
const
425 if (m_logLevels[LL_ON] && m_logLevels[logLevel])
427 char buf[MAX_LOG_MESSAGE_SIZE];
428 BaseString::vsnprintf(buf,
sizeof(buf), pMsg, ap);
430 while ( (pHandler = m_pHandlerList->
next()) != NULL)
432 pHandler->
append(m_pCategory, logLevel, buf);
437 void Logger::setRepeatFrequency(
unsigned val)
440 while ((pHandler = m_pHandlerList->
next()) != NULL)
442 pHandler->setRepeatFrequency(val);