#include <Log_Msg_NT_Event_Log.h>
Inheritance diagram for ACE_Log_Msg_NT_Event_Log:
Public Member Functions | |
ACE_Log_Msg_NT_Event_Log (void) | |
Constructor. | |
virtual | ~ACE_Log_Msg_NT_Event_Log (void) |
Destructor. | |
virtual int | open (const ACE_TCHAR *logger_key) |
Open a new event log. | |
virtual int | reset (void) |
Reset the backend. | |
virtual int | close (void) |
Close the backend completely. | |
virtual int | log (ACE_Log_Record &log_record) |
This is called when we want to log a message. | |
Private Attributes | |
HANDLE | evlog_handle_ |
Definition at line 35 of file Log_Msg_NT_Event_Log.h.
|
Constructor.
Definition at line 17 of file Log_Msg_NT_Event_Log.cpp.
00018 : evlog_handle_(0) 00019 { 00020 } |
|
Destructor.
Definition at line 22 of file Log_Msg_NT_Event_Log.cpp. References close().
00023 { 00024 this->close (); 00025 } |
|
Close the backend completely.
Implements ACE_Log_Msg_Backend. Definition at line 90 of file Log_Msg_NT_Event_Log.cpp. References evlog_handle_. Referenced by reset(), and ~ACE_Log_Msg_NT_Event_Log().
00091 { 00092 if (this->evlog_handle_ == 0 00093 || DeregisterEventSource (this->evlog_handle_)) 00094 { 00095 this->evlog_handle_ = 0; 00096 return 0; 00097 } 00098 else 00099 return -1; 00100 } |
|
This is called when we want to log a message.
Implements ACE_Log_Msg_Backend. Definition at line 103 of file Log_Msg_NT_Event_Log.cpp. References ACE_TCHAR, ACE_Log_Record::length(), LM_ALERT, LM_CRITICAL, LM_DEBUG, LM_EMERGENCY, LM_ERROR, LM_INFO, LM_NOTICE, LM_SHUTDOWN, LM_STARTUP, LM_TRACE, LM_WARNING, ACE_Log_Record::msg_data(), and ACE_Log_Record::type().
00104 { 00105 // Make a copy of the log text and replace any newlines with 00106 // CR-LF. Newline characters on their own do not appear correctly 00107 // in the event viewer. We allow for a doubling in the size of 00108 // the msg data for the worst case of all newlines. 00109 const ACE_TCHAR* src_msg_data = log_record.msg_data (); 00110 ACE_TCHAR msg_data [ACE_Log_Record::MAXLOGMSGLEN * 2]; 00111 00112 for (long i = 0, j = 0; i < log_record.length (); ++i) 00113 { 00114 if (src_msg_data[i] == '\n') 00115 { 00116 msg_data[j++] = '\r'; 00117 msg_data[j++] = '\n'; 00118 } 00119 else 00120 msg_data[j++] = src_msg_data[i]; 00121 } 00122 00123 // Map the ACE log record type to an event log type. 00124 WORD event_type; 00125 switch (log_record.type ()) 00126 { 00127 case LM_STARTUP: 00128 case LM_SHUTDOWN: 00129 case LM_TRACE: 00130 case LM_DEBUG: 00131 case LM_INFO: 00132 event_type = EVENTLOG_INFORMATION_TYPE; 00133 break; 00134 case LM_NOTICE: 00135 case LM_WARNING: 00136 event_type = EVENTLOG_WARNING_TYPE; 00137 break; 00138 case LM_ERROR: 00139 case LM_CRITICAL: 00140 case LM_ALERT: 00141 case LM_EMERGENCY: 00142 default: 00143 event_type = EVENTLOG_ERROR_TYPE; 00144 break; 00145 } 00146 00147 // Send the log message to the system event log. 00148 const ACE_TCHAR* msgs [1]; 00149 msgs[0] = msg_data; 00150 00151 if (ACE_TEXT_ReportEvent (this->evlog_handle_, 00152 event_type, 0, 0, 0, 1, 0, msgs, 0) == 0) 00153 return -1; 00154 else 00155 return 0; 00156 } |
|
Open a new event log. Initialize the event logging facility.
Implements ACE_Log_Msg_Backend. Definition at line 28 of file Log_Msg_NT_Event_Log.cpp. References ACE_LIB_TEXT, ACE_TCHAR, evlog_handle_, MAXPATHLEN, ACE_Log_Msg::program_name(), ACE_OS::strcpy(), ACE_OS::strlen(), and ACE_OS::strncat().
00029 { 00030 // ACE's "resource module" contains the message resource required 00031 // for event logging. 00032 ACE_TCHAR msg_file [MAXPATHLEN]; 00033 00034 if (!ACE_TEXT_GetModuleFileName (ACE_OS::get_win32_resource_module (), 00035 msg_file, 00036 MAXPATHLEN)) 00037 return -1; 00038 DWORD msg_file_length = 00039 static_cast<DWORD> ((ACE_OS::strlen (msg_file) + 1) * sizeof (ACE_TCHAR)); 00040 00041 // If a logger_key has been supplied then we use that as the event 00042 // source name, otherwise we default to the program name. 00043 const ACE_TCHAR *event_source_name = logger_key ? logger_key : ACE_Log_Msg::program_name (); 00044 00045 // Information is stored in the registry at a location based on the 00046 // program name. 00047 ACE_TCHAR reg_key [MAXPATHLEN]; 00048 ACE_OS::strcpy (reg_key, 00049 ACE_LIB_TEXT ("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\")); 00050 size_t reg_key_length = ACE_OS::strlen(reg_key); 00051 ACE_OS::strncat (reg_key, 00052 event_source_name, 00053 MAXPATHLEN - reg_key_length); 00054 00055 // Add the event source to the registry. Note that if this fails it 00056 // is not fatal. The application will still be able to write entries 00057 // to the event log, they just won't be formatted correctly. 00058 HKEY hkey; 00059 ACE_TEXT_RegCreateKey (HKEY_LOCAL_MACHINE, 00060 reg_key, 00061 &hkey); 00062 DWORD flags = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; 00063 ACE_TEXT_RegSetValueEx (hkey, 00064 ACE_LIB_TEXT ("TypesSupported"), 00065 0, 00066 REG_DWORD, 00067 (LPBYTE) &flags, 00068 sizeof (DWORD)); 00069 ACE_TEXT_RegSetValueEx (hkey, 00070 ACE_LIB_TEXT ("EventMessageFile"), 00071 0, 00072 REG_SZ, 00073 (LPBYTE) msg_file, 00074 msg_file_length); 00075 RegCloseKey (hkey); 00076 00077 // Obtain a handle to the event source. 00078 this->evlog_handle_ = ACE_TEXT_RegisterEventSource (0, 00079 event_source_name); 00080 return this->evlog_handle_ ? 0 : -1; 00081 } |
|
Reset the backend.
Implements ACE_Log_Msg_Backend. Definition at line 84 of file Log_Msg_NT_Event_Log.cpp. References close().
00085 { 00086 return this->close (); 00087 } |
|
Definition at line 64 of file Log_Msg_NT_Event_Log.h. |