summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/EventLoggerI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/EventLoggerI.cpp')
-rwxr-xr-xcpp/src/Ice/EventLoggerI.cpp90
1 files changed, 35 insertions, 55 deletions
diff --git a/cpp/src/Ice/EventLoggerI.cpp b/cpp/src/Ice/EventLoggerI.cpp
index 23e90e98c79..b52e6981624 100755
--- a/cpp/src/Ice/EventLoggerI.cpp
+++ b/cpp/src/Ice/EventLoggerI.cpp
@@ -10,14 +10,19 @@
#include <Ice/EventLoggerI.h>
#include <Ice/EventLoggerMsg.h>
#include <Ice/LocalException.h>
+#include <Ice/Network.h> // For errorToString
+#include <IceUtil/StaticMutex.h>
using namespace std;
-HMODULE Ice::EventLoggerI::_module = NULL;
+HMODULE Ice::EventLoggerI::_module = 0;
-Ice::EventLoggerI::EventLoggerI(const string& appName) :
- _appName(appName), _source(NULL)
+static IceUtil::StaticMutex outputMutex = ICE_STATIC_MUTEX_INITIALIZER;
+
+Ice::EventLoggerI::EventLoggerI(const string& theAppName) :
+ _source(0)
{
+ string appName = theAppName;
if(appName.empty())
{
InitializationException ex(__FILE__, __LINE__);
@@ -31,47 +36,27 @@ Ice::EventLoggerI::EventLoggerI(const string& appName) :
// The application name cannot contain backslashes.
//
string::size_type pos = 0;
- while((pos = _appName.find('\\', pos)) != string::npos)
+ while((pos = appName.find('\\', pos)) != string::npos)
{
- _appName[pos] = '/';
+ appName[pos] = '/';
}
- string key = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + _appName;
+ string key = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\" + appName;
HKEY hKey;
DWORD d;
- LONG err;
//
- // Try to create the key or gain full key access and set the values
+ // Try to create the key and set the values.
//
-
- bool setValues = true;
- err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, "REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0,
+ LONG err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, "REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0,
&hKey, &d);
- if(err != ERROR_SUCCESS)
- {
- //
- // If the key exist and I can read it, that's good enough ... we hope the values are set properly.
- //
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
- {
- setValues = false;
- }
- else
- {
- SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- throw ex;
- }
- }
-
- if(setValues)
+ if(err == ERROR_SUCCESS)
{
//
// Get the filename of this DLL.
//
char path[_MAX_PATH];
- assert(_module != NULL);
+ assert(_module != 0);
if(!GetModuleFileName(_module, path, _MAX_PATH))
{
RegCloseKey(hKey);
@@ -85,7 +70,7 @@ Ice::EventLoggerI::EventLoggerI(const string& appName) :
// "EventMessageFile" key should contain the path to this DLL.
//
err = RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ,
- (unsigned char*)path, static_cast<DWORD>(strlen(path) + 1));
+ reinterpret_cast<unsigned char*>(path), static_cast<DWORD>(strlen(path) + 1));
if(err != ERROR_SUCCESS)
{
RegCloseKey(hKey);
@@ -98,7 +83,8 @@ Ice::EventLoggerI::EventLoggerI(const string& appName) :
// The "TypesSupported" key indicates the supported event types.
//
DWORD typesSupported = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
- err = RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (unsigned char*)&typesSupported, sizeof(typesSupported));
+ err = RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, reinterpret_cast<unsigned char*>(&typesSupported),
+ sizeof(typesSupported));
if(err != ERROR_SUCCESS)
{
RegCloseKey(hKey);
@@ -106,15 +92,15 @@ Ice::EventLoggerI::EventLoggerI(const string& appName) :
ex.error = err;
throw ex;
}
+ RegCloseKey(hKey);
}
- RegCloseKey(hKey);
//
// The event source must match the registry key.
//
- _source = RegisterEventSource(NULL, _appName.c_str());
- if(_source == NULL)
+ _source = RegisterEventSource(0, appName.c_str());
+ if(_source == 0)
{
SyscallException ex(__FILE__, __LINE__);
ex.error = GetLastError();
@@ -124,10 +110,8 @@ Ice::EventLoggerI::EventLoggerI(const string& appName) :
Ice::EventLoggerI::~EventLoggerI()
{
- if(_source != NULL)
- {
- DeregisterEventSource(_source);
- }
+ assert(_source != 0);
+ DeregisterEventSource(_source);
}
void
@@ -135,11 +119,10 @@ Ice::EventLoggerI::print(const string& message)
{
const char* str[1];
str[0] = message.c_str();
- if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, NULL, 1, 0, str, NULL))
+ if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ IceUtil::StaticMutex::Lock sync(outputMutex);
+ cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
@@ -156,11 +139,10 @@ Ice::EventLoggerI::trace(const string& category, const string& message)
const char* str[1];
str[0] = s.c_str();
- if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, NULL, 1, 0, str, NULL))
+ if(!ReportEvent(_source, EVENTLOG_INFORMATION_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ IceUtil::StaticMutex::Lock sync(outputMutex);
+ cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
@@ -169,11 +151,10 @@ Ice::EventLoggerI::warning(const string& message)
{
const char* str[1];
str[0] = message.c_str();
- if(!ReportEvent(_source, EVENTLOG_WARNING_TYPE, 0, EVENT_LOGGER_MSG, NULL, 1, 0, str, NULL))
+ if(!ReportEvent(_source, EVENTLOG_WARNING_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ IceUtil::StaticMutex::Lock sync(outputMutex);
+ cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}
@@ -182,11 +163,10 @@ Ice::EventLoggerI::error(const string& message)
{
const char* str[1];
str[0] = message.c_str();
- if(!ReportEvent(_source, EVENTLOG_ERROR_TYPE, 0, EVENT_LOGGER_MSG, NULL, 1, 0, str, NULL))
+ if(!ReportEvent(_source, EVENTLOG_ERROR_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, str, 0))
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ IceUtil::StaticMutex::Lock sync(outputMutex);
+ cerr << "ReportEvent failed `" << IceInternal::errorToString(GetLastError()) << "':\n" << message << endl;
}
}