You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/18 17:01:13 UTC

svn commit: r805437 - in /commons/sandbox/runtime/trunk/src/main/native/os/win32: main.c syslog.c

Author: mturk
Date: Tue Aug 18 15:01:13 2009
New Revision: 805437

URL: http://svn.apache.org/viewvc?rev=805437&view=rev
Log:
Do not log to event log unles explicitly enabled

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=805437&r1=805436&r2=805437&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Tue Aug 18 15:01:13 2009
@@ -204,8 +204,23 @@
 {
     HKEY  key;
     DWORD ts;
-    char  *event_key = malloc(strlen(domain) + 64);
+    char   event_env[64] = "";
+    char  *event_key;
 
+    /* Check the environment variable.
+     * We are only interested in it's presense
+     */
+    if (!domain) {
+        if (GetEnvironmentVariableA("ACR_LOG_SYSLOG", event_env, 64) == 0)
+            return;
+        else
+            domain = &evant_env[0];
+        if (!*domain)
+            return;
+    }
+    event_key = malloc(strlen(domain) + 64);
+    if (!event_key)
+        return;
     lstrcpyA(event_key,
              "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
     lstrcatA(event_key, domain);
@@ -251,7 +266,7 @@
     /* Preload Late bound system libraries */
     if ((rc = preload_late_dlls()) != ERROR_SUCCESS) {
         /* Should never happen. */
-        acr_init_log_source(LOG_MSG_DOMAIN);
+        acr_init_log_source(NULL);
         do_syslog(ACR_LOG_ERROR,
                   L"Failed loading system libraries", rc);
         return (int)rc;
@@ -271,7 +286,7 @@
             WCHAR buf[128];
             swprintf(buf, L"Failed enabling %s", sePrivileges[i]);
             /* Log that we couldn't set privilege */
-            acr_init_log_source(LOG_MSG_DOMAIN);
+            acr_init_log_source(NULL);
             do_syslog(ACR_LOG_WARN, buf, rc);
         }
         i++;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c?rev=805437&r1=805436&r2=805437&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/syslog.c Tue Aug 18 15:01:13 2009
@@ -38,6 +38,8 @@
     DWORD id = LOG_MSG_DEBUG;
     WORD  il = EVENTLOG_SUCCESS;
     HANDLE source;
+    const WCHAR *et = L"";
+    FILE  *es = stderr;
     WCHAR *messages[2] = { NULL, NULL};
     WCHAR  buffer[ACR_MBUFF_SIZ] = L"";
     WORD   nStrings = 1;
@@ -46,22 +48,28 @@
         case ACR_LOG_EMERG:
             id = LOG_MSG_EMERG;
             il = EVENTLOG_ERROR_TYPE;
+            et = L"[EMERG]    :";
         break;
         case ACR_LOG_ERROR:
             id = LOG_MSG_ERROR;
             il = EVENTLOG_ERROR_TYPE;
+            et = L"[ERROR]    :";
         break;
         case ACR_LOG_NOTICE:
             id = LOG_MSG_NOTICE;
             il = EVENTLOG_WARNING_TYPE;
+            et = L"[NOTICE]   :";
         break;
         case ACR_LOG_WARN:
             id = LOG_MSG_WARN;
             il = EVENTLOG_WARNING_TYPE;
+            et = L"[WARNING] :";
         break;
         case ACR_LOG_INFO:
             id = LOG_MSG_INFO;
             il = EVENTLOG_INFORMATION_TYPE;
+            et = L"[INFO]    :";
+            es = stdout;
         break;
     }
 
@@ -77,16 +85,24 @@
         messages[1] = &buffer[0];
         nStrings = 2;
     }
-    source = RegisterEventSourceA(NULL, acr_log_domain);
+    if (acr_log_domain) {
+        source = RegisterEventSourceA(NULL, acr_log_domain);
 
-    if (source != NULL) {
-        ReportEventW(source, il,
-                     0,
-                     id,
-                     NULL,
-                     nStrings, 0,
-                     messages, NULL);
-        DeregisterEventSource(source);
+        if (source != NULL) {
+            ReportEventW(source, il,
+                         0,
+                         id,
+                         NULL,
+                         nStrings, 0,
+                         messages, NULL);
+            DeregisterEventSource(source);
+        }
+    }
+    else {
+        fprintf(es, "%S%S\n", et, messages[0]);
+        if (messages[1])
+            fprintf(es, "           %S\n", et, messages[0]);
+        fflush(es);
     }
 }
 
@@ -115,3 +131,4 @@
         do_syslog(level, J2W(msg), 0);
     } END_WITH_WSTR(msg);
 }
+