diff options
-rw-r--r-- | src/anytun.cpp | 2 | ||||
-rw-r--r-- | src/log.cpp | 13 | ||||
-rw-r--r-- | src/log.h | 7 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp index 59aeb32..292d924 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -444,7 +444,7 @@ int main(int argc, char* argv[]) } if (connect_to.begin() == connect_to.end() || gOpt.getDevType()!="tun") { - cLog.msg(Log::PRIO_NOTICE) << "No sync/controll host defined or not a tun device. Disabling multi connection support (routing)"; + cLog.msg(Log::PRIO_NOTICE) << "No sync/control host defined or not a tun device. Disabling multi connection support (routing)"; disableRouting=true; } #endif diff --git a/src/log.cpp b/src/log.cpp index 60f6e54..026a851 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -100,6 +100,10 @@ Log::~Log() #ifdef LOG_SYSLOG closelog(); #endif +#ifdef LOG_FILE + if(log_file.is_open()) + log_file.close(); +#endif #ifdef LOG_WINEVENTLOG if(h_event_source_) DeregisterEventSource(h_event_source_); @@ -111,6 +115,9 @@ void Log::open() #ifdef LOG_SYSLOG openlog(logName.c_str(), LOG_PID, facility); #endif +#ifdef LOG_FILE + log_file.open("anytun.log", std::fstream::out | std::fstream::app); +#endif #ifdef LOG_WINEVENTLOG h_event_source_ = RegisterEventSourceA(NULL, logName.c_str()); #endif @@ -125,6 +132,10 @@ void Log::log(std::string msg, int prio) #ifdef LOG_STDOUT std::cout << "LOG-" << Log::prioToString(prio) << ": " << msg << std::endl; #endif +#ifdef LOG_FILE + if(log_file.is_open()) + log_file << Log::prioToString(prio) << ": " << msg << std::endl; +#endif #ifdef LOG_WINEVENTLOG LPCTSTR lpszStrings[1]; CHAR buffer[STERROR_TEXT_MAX]; @@ -135,7 +146,7 @@ void Log::log(std::string msg, int prio) #endif } -#ifdef LOG_STDOUT +#if defined(LOG_STDOUT) || defined(LOG_FILE) std::string Log::prioToString(int prio) { switch(prio) { @@ -34,6 +34,8 @@ #include <string> #include <sstream> +#include <fstream> + #ifdef LOG_SYSLOG #include <syslog.h> #endif @@ -144,7 +146,7 @@ public: static const int PRIO_INFO = 7; static const int PRIO_DEBUG = 8; #endif -#ifdef LOG_STDOUT +#if defined(LOG_STDOUT) || defined(LOG_FILE) static std::string prioToString(int prio); #endif #ifdef LOG_WINEVENTLOG @@ -184,6 +186,9 @@ private: std::string logName; int facility; +#ifdef LOG_FILE + std::ofstream log_file; +#endif #ifdef LOG_WINEVENTLOG HANDLE h_event_source_; #endif |