Author: carnold
Date: Mon Feb 18 17:12:36 2008
New Revision: 628945

URL: http://svn.apache.org/viewvc?rev=628945&view=rev
Log:
LOGCXX-67: Add event messages for NTEventLogAppender

Added:
    logging/log4cxx/trunk/src/main/resources/   (with props)
    logging/log4cxx/trunk/src/main/resources/EventLogCategories.mc
      - copied unchanged from r628870, 
logging/log4j/trunk/src/ntdll/EventLogCategories.mc
    logging/log4cxx/trunk/src/main/resources/MSG00001.bin
      - copied unchanged from r628870, 
logging/log4j/trunk/src/ntdll/MSG00001.bin
    logging/log4cxx/trunk/src/main/resources/log4cxx.rc
      - copied, changed from r628870, 
logging/log4j/trunk/src/ntdll/NTEventLogAppender.rc
Modified:
    logging/log4cxx/trunk/build.xml
    logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp
    logging/log4cxx/trunk/src/main/cpp/transcoder.cpp
    logging/log4cxx/trunk/src/main/include/log4cxx/helpers/transcoder.h
    logging/log4cxx/trunk/src/main/include/log4cxx/nt/nteventlogappender.h

Modified: logging/log4cxx/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/build.xml?rev=628945&r1=628944&r2=628945&view=diff
==============================================================================
--- logging/log4cxx/trunk/build.xml (original)
+++ logging/log4cxx/trunk/build.xml Mon Feb 18 17:12:36 2008
@@ -68,6 +68,7 @@
 
 <property name="base.dir" location="."/>
 <property name="src.dir" location="${base.dir}/src/main/cpp"/>
+<property name="resources.dir" location="${base.dir}/src/main/resources"/>
 <property name="include.dir" location="${base.dir}/src/main/include"/>
 <property name="target.dir" location="${base.dir}/target"/>
 <property name="lib.dir" location="${target.dir}/lib"/>
@@ -526,6 +527,11 @@
 
     <property name="project.compiler" value="${compiler}"/>
    <property name="project.type" value="msvc6"/>
+
+  <condition property="resource.compiler" value="windres">
+    <isset property="is-gcc"/>
+  </condition>
+  <property name="resource.compiler" value="msrc"/>
     
     <cc name="${project.compiler}"
                 exceptions="true"
@@ -536,6 +542,10 @@
                 objdir="${log4cxx.lib.dir}/log4cxx_obj"
                 debug="${debug}"
                 projectsOnly="${projectsOnly}">
+        <compiler name="${resource.compiler}" if="is-windows">
+          <includepath path="${resources.dir}"/>
+          <fileset dir="${resources.dir}" includes="*.rc"/>
+        </compiler>
         <fileset dir="${src.dir}" includes="*.cpp"/>
         <fileset dir="${include.dir}" includes="**/*.h"/>
         <includepath path="${include.dir}"/>
@@ -702,7 +712,12 @@
     <mkdir dir="${executable.dir}/static/testsuite-standalone_obj"/>
     <property name="project.compiler" value="${compiler}"/>
    <property name="project.type" value="msvc6"/>
-    <cc name="${project.compiler}"
+  <condition property="resource.compiler" value="windres">
+    <isset property="is-gcc"/>
+  </condition>
+  <property name="resource.compiler" value="msrc"/>
+
+  <cc name="${project.compiler}"
                 exceptions="true"
                 outfile="${executable.dir}/static/testsuite-standalone"
                 subsystem="console"
@@ -712,6 +727,10 @@
                 objdir="${executable.dir}/static/testsuite-standalone_obj"
                 debug="${debug}"
                 projectsOnly="${projectsOnly}">
+        <compiler name="${resource.compiler}" if="is-windows">
+          <includepath path="${resources.dir}"/>
+          <fileset dir="${resources.dir}" includes="*.rc"/>
+        </compiler>
         <fileset dir="${src.dir}" includes="*.cpp" 
excludes="**/iconv_module.cpp"/>
         <fileset dir="${include.dir}" includes="**/*.h"/>
         <fileset dir="${tests.cpp.dir}" includes="**/*.cpp **/*.c **/*.h"/>

Modified: logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp?rev=628945&r1=628944&r2=628945&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/nteventlogappender.cpp Mon Feb 18 
17:12:36 2008
@@ -165,19 +165,11 @@
 
         addRegistryInfo();
 
-#if LOG4CXX_WCHAR_T_API
         LOG4CXX_ENCODE_WCHAR(wsource, source);
         LOG4CXX_ENCODE_WCHAR(wserver, server);
         hEventLog = ::RegisterEventSourceW(
             wserver.empty() ? NULL : wserver.c_str(),
             wsource.c_str());
-#else
-        LOG4CXX_ENCODE_CHAR(wsource, source);
-        LOG4CXX_ENCODE_CHAR(wserver, server);
-        hEventLog = ::RegisterEventSourceA(
-            wserver.empty() ? NULL : wserver.c_str(),
-            wsource.c_str());
-#endif
         if (hEventLog == NULL) {
             LogString msg(LOG4CXX_STR("Cannot register NT EventLog -- server: 
'"));
             msg.append(server);
@@ -198,7 +190,6 @@
 
         LogString oss;
         layout->format(oss, event, p);
-#if LOG4CXX_WCHAR_T_API
         wchar_t* msgs = Transcoder::wencode(oss, p);
         BOOL bSuccess = ::ReportEventW(
                 hEventLog,
@@ -210,19 +201,6 @@
                 0,
                 (LPCWSTR*) &msgs,
                 NULL);
-#else
-        char* msgs = Transcoder::encode(oss, p);
-        BOOL bSuccess = ::ReportEventA(
-                hEventLog,
-                getEventType(event),
-                getEventCategory(event),
-                0x1000,
-                pCurrentUserSID,
-                1,
-                0,
-                &msgs,
-                NULL);
-#endif
 
         if (!bSuccess)
         {
@@ -230,55 +208,42 @@
         }
 }
 
-NTEventLogAppender::HKEY NTEventLogAppender::regGetKey(
-     const LogString& subkey, DWORD *disposition)
-{
-        ::HKEY hkey = 0;
-#if LOG4CXX_WCHAR_T_API
-        LOG4CXX_ENCODE_WCHAR(wstr, subkey);
-        RegCreateKeyExW((::HKEY) HKEY_LOCAL_MACHINE, wstr.c_str(), 0, NULL,
-                REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL,
-                &hkey, disposition);
-#else
-        LOG4CXX_ENCODE_CHAR(str, subkey);
-        RegCreateKeyExA((::HKEY) HKEY_LOCAL_MACHINE, str.c_str(), 0, NULL,
-                REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL,
-                &hkey, disposition);
-#endif
-        return hkey;
-}
-
-void NTEventLogAppender::regSetString(HKEY hkey, const wchar_t*  name,
-                                       const wchar_t* value)
-{
-        RegSetValueExW((::HKEY) hkey, name, 0, REG_SZ, (LPBYTE) value,
-        wcslen(value)*sizeof(wchar_t));
-}
-
-void NTEventLogAppender::regSetDword(HKEY hkey, const wchar_t* name, DWORD 
value)
-{
-        RegSetValueExW((::HKEY) hkey, name, 0, REG_DWORD, (LPBYTE)&value, 
sizeof(DWORD));
-}
-
 /*
  * Add this source with appropriate configuration keys to the registry.
  */
 void NTEventLogAppender::addRegistryInfo()
 {
-        DWORD disposition;
+        DWORD disposition = 0;
         ::HKEY hkey = 0;
         LogString 
subkey(LOG4CXX_STR("SYSTEM\\CurrentControlSet\\Services\\EventLog\\"));
         subkey.append(log);
         subkey.append(1, 0x5C /* '\\' */);
         subkey.append(source);
+        LOG4CXX_ENCODE_WCHAR(wsource, source);
 
-        hkey = (::HKEY) regGetKey(subkey, &disposition);
-        if (disposition == REG_CREATED_NEW_KEY)
-        {
-                regSetString(hkey, L"EventMessageFile", 
L"NTEventLogAppender.dll");
-                regSetString(hkey, L"CategoryMessageFile", 
L"NTEventLogAppender.dll");
-                regSetDword(hkey,  L"TypesSupported", (DWORD)7);
-                regSetDword(hkey,  L"CategoryCount", (DWORD)5);
+        long stat = RegCreateKeyExW(HKEY_LOCAL_MACHINE, wsource.c_str(), 0, 
NULL,
+                REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL,
+                &hkey, &disposition);
+        if (stat == ERROR_SUCCESS && disposition == REG_CREATED_NEW_KEY) {
+            HMODULE hmodule = GetModuleHandleW(L"log4cxx");
+            if (hmodule == NULL) {
+                hmodule = GetModuleHandleW(0);
+            }
+            wchar_t modpath[_MAX_PATH];
+            DWORD modlen = GetModuleFileNameW(hmodule, modpath, _MAX_PATH - 1);
+            if (modlen > 0) {
+                modpath[modlen] = 0;
+                RegSetValueExW(hkey, L"EventMessageFile", 0, REG_SZ, 
+                        (LPBYTE) modpath, wcslen(modpath) * sizeof(wchar_t));
+                RegSetValueExW(hkey, L"CategoryMessageFile", 0, REG_SZ, 
+                        (LPBYTE) modpath, wcslen(modpath) * sizeof(wchar_t));
+                    DWORD typesSupported = 7;
+                    DWORD categoryCount = 6;
+                RegSetValueExW(hkey, L"TypesSupported", 0, REG_DWORD, 
+                           (LPBYTE)&typesSupported, sizeof(DWORD));
+                RegSetValueExW(hkey, L"CategoryCount", 0, REG_DWORD, 
+                           (LPBYTE)&categoryCount, sizeof(DWORD));
+            }
         }
 
         RegCloseKey(hkey);
@@ -287,52 +252,40 @@
 
 WORD NTEventLogAppender::getEventType(const LoggingEventPtr& event)
 {
-        WORD ret_val;
-
-        switch (event->getLevel()->toInt())
-        {
-        case Level::FATAL_INT:
-        case Level::ERROR_INT:
-                ret_val = EVENTLOG_ERROR_TYPE;
-                break;
-        case Level::WARN_INT:
-                ret_val = EVENTLOG_WARNING_TYPE;
-                break;
-        case Level::INFO_INT:
-        case Level::DEBUG_INT:
-        default:
-                ret_val = EVENTLOG_INFORMATION_TYPE;
-                break;
-        }
-
-        return ret_val;
+  int priority = event->getLevel()->toInt();
+  WORD type = EVENTLOG_SUCCESS;
+  if (priority >= Level::INFO_INT) {
+      type = EVENTLOG_INFORMATION_TYPE;
+      if (priority >= Level::WARN_INT) {
+          type = EVENTLOG_WARNING_TYPE;
+          if (priority >= Level::ERROR_INT) {
+             type = EVENTLOG_ERROR_TYPE;
+          }
+      }
+  }
+  return type;
 }
 
 WORD NTEventLogAppender::getEventCategory(const LoggingEventPtr& event)
 {
-        WORD ret_val;
-
-        switch (event->getLevel()->toInt())
-        {
-        case Level::FATAL_INT:
-                ret_val = 1;
-                break;
-        case Level::ERROR_INT:
-                ret_val = 2;
-                break;
-        case Level::WARN_INT:
-                ret_val = 3;
-                break;
-        case Level::INFO_INT:
-                ret_val = 4;
-                break;
-        case Level::DEBUG_INT:
-        default:
-                ret_val = 5;
-                break;
-        }
-
-        return ret_val;
+  int priority = event->getLevel()->toInt();
+  WORD category = 1;
+  if (priority >= Level::DEBUG_INT) {
+      category = 2;
+      if (priority >= Level::INFO_INT) {
+          category = 3;
+          if (priority >= Level::WARN_INT) {
+             category = 4;
+             if (priority >= Level::ERROR_INT) {
+                category = 5;
+                if (priority >= Level::FATAL_INT) {
+                    category = 6;
+                }
+             }
+          }
+      }
+  }
+  return category;
 }
 
 LogString NTEventLogAppender::getErrorString(const LogString& function)
@@ -340,7 +293,6 @@
     Pool p;
     enum { MSGSIZE = 5000 };
 
-#if LOG4CXX_WCHAR_T_API
     wchar_t* lpMsgBuf = (wchar_t*) p.palloc(MSGSIZE * sizeof(wchar_t));
     DWORD dw = GetLastError();
 
@@ -351,19 +303,6 @@
         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
         lpMsgBuf,
         MSGSIZE, NULL );
-#else
-    char* lpMsgBuf = (char*) p.palloc(MSGSIZE);
-    DWORD dw = GetLastError();
-
-    FormatMessageA(
-        FORMAT_MESSAGE_FROM_SYSTEM,
-        NULL,
-        dw,
-        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-        lpMsgBuf,
-        MSGSIZE, NULL );
-
-#endif
 
     LogString msg(function);
     msg.append(LOG4CXX_STR(" failed with error "));

Modified: logging/log4cxx/trunk/src/main/cpp/transcoder.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/transcoder.cpp?rev=628945&r1=628944&r2=628945&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/transcoder.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/transcoder.cpp Mon Feb 18 17:12:36 2008
@@ -362,7 +362,7 @@
 
 
 
-#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T || defined(WIN32) || 
defined(_WIN32)
 void Transcoder::decode(const std::wstring& src, LogString& dst) {
 #if LOG4CXX_LOGCHAR_IS_WCHAR_T
   dst.append(src, len);

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/transcoder.h
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/transcoder.h?rev=628945&r1=628944&r2=628945&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/transcoder.h 
(original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/transcoder.h Mon Feb 
18 17:12:36 2008
@@ -106,7 +106,7 @@
 
 
 
-#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T
+#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T || defined(WIN32) || 
defined(_WIN32)
       static void decode(const std::wstring& src, LogString& dst);
       static void encode(const LogString& src, std::wstring& dst);
       static wchar_t* wencode(const LogString& src, log4cxx::helpers::Pool& p);

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/nt/nteventlogappender.h
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/nt/nteventlogappender.h?rev=628945&r1=628944&r2=628945&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/nt/nteventlogappender.h 
(original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/nt/nteventlogappender.h Mon 
Feb 18 17:12:36 2008
@@ -79,16 +79,12 @@
                         //   these typedef are proxies for the real Win32 
definitions
                         //     and need to be cast to the global definitions 
before
                         //     use with a Win32 API call
-                        typedef void* HKEY;
                         typedef void SID;
                         typedef void* HANDLE;
 
                         virtual void append(const spi::LoggingEventPtr& event, 
log4cxx::helpers::Pool& p);
-                        static HKEY regGetKey(const LogString& subkey, 
unsigned long *disposition);
-                        static void regSetString(HKEY hkey, const wchar_t* 
name, const wchar_t* value);
-                        static void regSetDword(HKEY hkey, const wchar_t* 
name, unsigned long value);
-                        unsigned short getEventType(const 
spi::LoggingEventPtr& event);
-                        unsigned short getEventCategory(const 
spi::LoggingEventPtr& event);
+                        static unsigned short getEventType(const 
spi::LoggingEventPtr& event);
+                        static unsigned short getEventCategory(const 
spi::LoggingEventPtr& event);
                         /*
                          * Add this source with appropriate configuration keys 
to the registry.
                          */

Propchange: logging/log4cxx/trunk/src/main/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 18 17:12:36 2008
@@ -0,0 +1 @@
+log4cxx.aps

Copied: logging/log4cxx/trunk/src/main/resources/log4cxx.rc (from r628870, 
logging/log4j/trunk/src/ntdll/NTEventLogAppender.rc)
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/resources/log4cxx.rc?p2=logging/log4cxx/trunk/src/main/resources/log4cxx.rc&p1=logging/log4j/trunk/src/ntdll/NTEventLogAppender.rc&r1=628870&r2=628945&rev=628945&view=diff
==============================================================================
--- logging/log4j/trunk/src/ntdll/NTEventLogAppender.rc (original)
+++ logging/log4cxx/trunk/src/main/resources/log4cxx.rc Mon Feb 18 17:12:36 2008
@@ -76,8 +76,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION  1, 2, 15, 1
- PRODUCTVERSION 1, 2, 15, 1
+ FILEVERSION  0, 10, 0, 1
+ PRODUCTVERSION 0, 10, 0, 1
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -93,13 +93,13 @@
         BLOCK "040904b0"
         BEGIN
             VALUE "CompanyName", "Apache Software Foundation"
-            VALUE "FileDescription", "Platform methods for NTEventLogAppender"
-            VALUE "FileVersion", "1, 2, 15, 1"
-            VALUE "InternalName", "NTEventLogAppender"
+            VALUE "FileDescription", "Apache log4cxx"
+            VALUE "FileVersion", "0,10, 0, 1"
+            VALUE "InternalName", "log4cxx"
             VALUE "LegalCopyright",  "Licensed to the Apache Software 
Foundation (ASF) under one or more\ncontributor license agreements.  See the 
NOTICE file distributed with\nthis work for additional information regarding 
copyright ownership.\nThe ASF licenses this file to You under the Apache 
License, Version 2.0\n(the ""License""); you may not use this file except in 
compliance with\nthe License.  You may obtain a copy of the License at\n\n     
http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law 
or agreed to in writing, software\ndistributed under the License is distributed 
on an ""AS IS"" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied.\nSee the License for the specific language governing 
permissions and\nlimitations under the License."
-            VALUE "OriginalFilename", "NTEventLogAppender.dll"
-            VALUE "ProductName", "Apache log4j"
-            VALUE "ProductVersion", "1, 2, 15, 1" 
+            VALUE "OriginalFilename", "log4cxx.dll"
+            VALUE "ProductName", "Apache log4cxx"
+            VALUE "ProductVersion", "0, 10, 0, 1" 
         END
     END
     BLOCK "VarFileInfo"


Reply via email to