ringbuffer.h \
socket.cpp \
socket.h \
+ sysloglogger.cpp \
+ sysloglogger.h \
tcpclient.cpp \
tcpclient.h \
tcpserver.cpp \
#ifdef _WIN32
HMODULE hModule = LoadLibrary(path.c_str());
+
+ if (hModule == NULL)
+ throw Win32Exception("LoadLibrary('" + path + "') failed", GetLastError());
#else /* _WIN32 */
lt_dlhandle hModule = lt_dlopen(path.c_str());
-#endif /* _WIN32 */
- if (hModule == NULL)
- throw runtime_error("Could not load module");
+ if (hModule == NULL) {
+ throw runtime_error("Could not load module '" + path + "': " + lt_dlerror());
+ }
+#endif /* _WIN32 */
#ifdef _WIN32
pCreateComponent = (CreateComponentFunction)GetProcAddress(hModule,
}
/**
- * Retrieves the directory the application's binary is contained in.
+ * Retrieves the full path of the executable.
*
- * @returns The directory.
+ * @returns The path.
*/
-string Application::GetExeDirectory(void) const
+string Application::GetExePath(void) const
{
static string result;
if (realpath(executablePath.c_str(), buffer) == NULL)
throw PosixException("realpath failed", errno);
- executablePath = buffer;
+ result = buffer;
#else /* _WIN32 */
char FullExePath[MAXPATHLEN];
if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath)))
throw Win32Exception("GetModuleFileName() failed", GetLastError());
- executablePath = FullExePath;
+ result = FullExePath;
#endif /* _WIN32 */
- result = Utility::DirName(executablePath);
-
return result;
}
protected:
void RunEventLoop(void);
- string GetExeDirectory(void) const;
+ string GetExePath(void) const;
private:
static Application::Ptr m_Instance; /**< The application instance. */
{
/**
- * A logger that logs to stderr.
+ * A logger that logs to stdout.
*/
class ConsoleLogger : public Logger
{
#include "threadpool.h"
#include "logger.h"
#include "consolelogger.h"
+#include "sysloglogger.h"
#endif /* I2BASE_H */
--- /dev/null
+#include "i2-base.h"
+
+using namespace icinga;
+
+/**
+ * Constructor for the SyslogLogger class.
+ *
+ * @param minSeverity Minimum severity for log messages.
+ */
+SyslogLogger::SyslogLogger(const string& ident, LogSeverity minSeverity)
+ : Logger(minSeverity)
+{
+// openlog(ident.c_str(), 0, LOG_USER);
+}
+
+/**
+ * Processes a log entry and outputs it to syslog.
+ *
+ * @param entry The log entry.
+ */
+void SyslogLogger::ProcessLogEntry(const LogEntry& entry)
+{
+ char timestamp[100];
+
+ int severity;
+ switch (entry.Severity) {
+ case LogDebug:
+ severity = LOG_DEBUG;
+ break;
+ case LogInformation:
+ severity = LOG_INFO;
+ break;
+ case LogWarning:
+ severity = LOG_WARNING;
+ break;
+ case LogCritical:
+ severity = LOG_CRIT;
+ break;
+ default:
+ assert(!"Invalid severity specified.");
+ }
+
+ syslog(severity | LOG_USER, "%s", entry.Message.c_str());
+}
--- /dev/null
+#ifndef SYSLOGLOGGER_H
+#define SYSLOGLOGGER_H
+
+namespace icinga
+{
+
+/**
+ * A logger that logs to syslog.
+ */
+class SyslogLogger : public Logger
+{
+public:
+ SyslogLogger(const string& ident, LogSeverity minSeverity);
+
+protected:
+ virtual void ProcessLogEntry(const LogEntry& entry);
+};
+
+}
+
+#endif /* SYSLOGLOGGER_H */
#include <pthread.h>
#include <signal.h>
#include <libgen.h>
+#include <syslog.h>
void Sleep(unsigned long milliseconds);
ConsoleLogger::Ptr consoleLogger = boost::make_shared<ConsoleLogger>(LogInformation);
Logger::RegisterLogger(consoleLogger);
+ SyslogLogger::Ptr syslogLogger = boost::make_shared<SyslogLogger>("icinga", LogDebug);
+ Logger::RegisterLogger(syslogLogger);
+
#ifdef _WIN32
Logger::Write(LogInformation, "icinga", "Icinga component loader");
#else /* _WIN32 */
return EXIT_FAILURE;
}
- string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
+ string componentDirectory = Utility::DirName(GetExePath()) + "/../lib/icinga2";
AddComponentSearchDir(componentDirectory);
/* register handler for 'component' config objects */