summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-02-20 06:49:27 +0000
committerChristian Pointner <equinox@anytun.org>2009-02-20 06:49:27 +0000
commit9e2398cd2195370f428bcdcd8cbd852d2fccc56a (patch)
treec503bec6b18afc9ee9b572938be763451aa7a922
parentcode cleanup (diff)
moved NO_SYSLOG to inverse LOG_SYSLOG switch
added LOG_WINEVENTLOG (experimental)
-rw-r--r--src/anytun.suobin60416 -> 61952 bytes
-rw-r--r--src/anytun.vcproj4
-rw-r--r--src/log.cpp44
-rw-r--r--src/log.h17
4 files changed, 54 insertions, 11 deletions
diff --git a/src/anytun.suo b/src/anytun.suo
index 24a6b07..084470a 100644
--- a/src/anytun.suo
+++ b/src/anytun.suo
Binary files differ
diff --git a/src/anytun.vcproj b/src/anytun.vcproj
index c96f1e6..a74e715 100644
--- a/src/anytun.vcproj
+++ b/src/anytun.vcproj
@@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="/I &quot;C:\Program Files\boost\boost_1_35_0\&quot;"
Optimization="0"
- PreprocessorDefinitions="LOG_STDOUT;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;NO_SYSLOG;NO_SIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
+ PreprocessorDefinitions="LOG_STDOUT;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;NO_SIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@@ -116,7 +116,7 @@
/>
<Tool
Name="VCCLCompilerTool"
- PreprocessorDefinitions="USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;NO_SYSLOG;NO_SIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
+ PreprocessorDefinitions="USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;NO_SIGNALCONTROLLER;WIN32_LEAN_AND_MEAN"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
diff --git a/src/log.cpp b/src/log.cpp
index 6ffc560..cdb8577 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -36,6 +36,11 @@
#include "threadUtils.hpp"
+#ifdef LOG_WINEVENTLOG
+#include <windows.h>
+#include <strsafe.h>
+#endif
+
Log* Log::inst = NULL;
Mutex Log::instMutex;
Log& cLog = Log::instance();
@@ -71,12 +76,20 @@ LogStringBuilder::LogStringBuilder(Log& l, int p) : log(l), prio(p)
LogStringBuilder::~LogStringBuilder()
{
Lock lock(log.mutex);
-#ifndef NO_SYSLOG
+#ifdef LOG_SYSLOG
syslog(prio | log.getFacility(), "%s", stream.str().c_str());
#endif
#ifdef LOG_STDOUT
std::cout << "LOG-" << Log::prioToString(prio) << ": " << stream.str() << std::endl;
#endif
+#ifdef LOG_WINEVENTLOG
+ LPCTSTR lpszStrings[1];
+ CHAR buffer[STERROR_TEXT_MAX];
+ StringCchPrintfA(buffer, STERROR_TEXT_MAX, "%s", stream.str().c_str());
+ lpszStrings[0] = buffer;
+ if(log.h_event_source_)
+ ReportEventA(log.h_event_source_, Log::prioToEventLogType(prio), 0, prio, NULL, 1, 0, lpszStrings, NULL);
+#endif
}
Log& Log::instance()
@@ -98,12 +111,16 @@ Log::Log()
Log::~Log()
{
-#ifndef NO_SYSLOG
+#ifdef LOG_SYSLOG
closelog();
#endif
+#ifdef LOG_WINEVENTLOG
+ if(h_event_source_)
+ DeregisterEventSource(h_event_source_);
+#endif
}
-#ifdef NO_SYSLOG
+#ifdef LOG_STDOUT
std::string Log::prioToString(int prio)
{
switch(prio) {
@@ -119,12 +136,31 @@ std::string Log::prioToString(int prio)
}
}
#endif
+#ifdef LOG_WINEVENTLOG
+WORD Log::prioToEventLogType(int prio)
+{
+ switch(prio) {
+ case PRIO_EMERG: return EVENTLOG_ERROR_TYPE;
+ case PRIO_ALERT: return EVENTLOG_ERROR_TYPE;
+ case PRIO_CRIT: return EVENTLOG_ERROR_TYPE;
+ case PRIO_ERR: return EVENTLOG_ERROR_TYPE;
+ case PRIO_WARNING: return EVENTLOG_WARNING_TYPE;
+ case PRIO_NOTICE: return EVENTLOG_INFORMATION_TYPE;
+ case PRIO_INFO: return EVENTLOG_SUCCESS;
+ case PRIO_DEBUG: return EVENTLOG_INFORMATION_TYPE;
+ default: return EVENTLOG_ERROR_TYPE;
+ }
+}
+#endif
void Log::open()
{
-#ifndef NO_SYSLOG
+#ifdef LOG_SYSLOG
openlog(logName.c_str(), LOG_PID, facility);
#endif
+#ifdef LOG_WINEVENTLOG
+ h_event_source_ = RegisterEventSourceA(NULL, logName.c_str());
+#endif
}
Log& Log::setLogName(std::string newLogName)
diff --git a/src/log.h b/src/log.h
index de6da92..6975ed5 100644
--- a/src/log.h
+++ b/src/log.h
@@ -34,14 +34,13 @@
#include <string>
#include <sstream>
-#ifndef NO_SYSLOG
+#ifdef LOG_SYSLOG
#include <syslog.h>
#endif
#include "threadUtils.hpp"
-
-#define STERROR_TEXT_MAX 100
+#define STERROR_TEXT_MAX 200
#ifndef NO_CRYPT
#ifndef USE_SSL_CRYPTO
@@ -86,7 +85,7 @@ private:
class Log : public std::ostringstream
{
public:
-#ifndef NO_SYSLOG
+#ifdef LOG_SYSLOG
static const int FAC_USER = LOG_USER;
static const int FAC_MAIL = LOG_MAIL;
static const int FAC_DAEMON = LOG_DAEMON;
@@ -144,9 +143,14 @@ public:
static const int PRIO_NOTICE = 6;
static const int PRIO_INFO = 7;
static const int PRIO_DEBUG = 8;
-
+#endif
+#ifdef LOG_STDOUT
static std::string prioToString(int prio);
#endif
+#ifdef LOG_WINEVENTLOG
+ static WORD prioToEventLogType(int prio);
+#endif
+
static Log& instance();
@@ -180,6 +184,9 @@ private:
std::string logName;
int facility;
+#ifdef LOG_WINEVENTLOG
+ HANDLE h_event_source_;
+#endif
};
extern Log& cLog;