You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/11/11 13:36:34 UTC

[commons-daemon] branch master updated: Log the prunsrv function names at the Trace level.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new b5cb234  Log the prunsrv function names at the Trace level.
b5cb234 is described below

commit b5cb234b4df1bd10757e01e4f5f7116073554c2a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Nov 11 08:36:32 2021 -0500

    Log the prunsrv function names at the Trace level.
---
 src/changes/changes.xml                   |  3 +++
 src/native/windows/apps/prunsrv/prunsrv.c |  2 +-
 src/native/windows/include/log.h          | 15 ++++++++-------
 src/native/windows/src/log.c              | 32 +++++++++++++++++++------------
 4 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b77e331..1f69f9c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -59,6 +59,9 @@
       <action type="fix" dev="ggregory" due-to="Gary Gregory">
         Miscellaneous logging improvements.
       </action>      
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">
+        Log the prunsrv function names at the Trace level.
+      </action>      
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="John Patrick">
         Enable Dependabot #20.
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index ddcbd3d..5daf14d 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -1053,7 +1053,7 @@ static BOOL reportServiceStatusE(DWORD dwLevel,
    static DWORD dwCheckPoint = 1;
    BOOL fResult = TRUE;
 
-   apxLogWrite(NULL, dwLevel, TRUE, __FILE__, __LINE__,
+   apxLogWrite(NULL, dwLevel, TRUE, __FILE__, __LINE__, __func__,
        "reportServiceStatusE: dwCurrentState = %d (%s), dwWin32ExitCode = %d, dwWaitHint = %d milliseconds, dwServiceSpecificExitCode = %d.",
        dwCurrentState, apxServiceGetStateName(dwCurrentState), dwWin32ExitCode, dwWaitHint, dwServiceSpecificExitCode);
 
diff --git a/src/native/windows/include/log.h b/src/native/windows/include/log.h
index 9188e1e..894a58e 100644
--- a/src/native/windows/include/log.h
+++ b/src/native/windows/include/log.h
@@ -54,13 +54,13 @@ __APXBEGIN_DECLS
 #define APXLOG_LEVEL_WARN   3
 #define APXLOG_LEVEL_ERROR  4
 
-#define APXLOG_MARK_INFO    NULL, APXLOG_LEVEL_INFO,  TRUE,  __FILE__, __LINE__, ""
-#define APXLOG_MARK_WARN    NULL, APXLOG_LEVEL_WARN,  TRUE,  __FILE__, __LINE__, ""
-#define APXLOG_MARK_ERROR   NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, __LINE__, ""
-#define APXLOG_MARK_DEBUG   NULL, APXLOG_LEVEL_DEBUG, TRUE,  __FILE__, __LINE__, ""
-#define APXLOG_MARK_TRACE   NULL, APXLOG_LEVEL_TRACE, TRUE,  __FILE__, __LINE__, ""
-#define APXLOG_MARK_RAW     NULL, APXLOG_LEVEL_INFO,  FALSE, NULL, 0,
-#define APXLOG_MARK_SYSERR  NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, __LINE__, NULL
+#define APXLOG_MARK_INFO    NULL, APXLOG_LEVEL_INFO,  TRUE,  __FILE__, __LINE__, __func__, ""
+#define APXLOG_MARK_WARN    NULL, APXLOG_LEVEL_WARN,  TRUE,  __FILE__, __LINE__, __func__, ""
+#define APXLOG_MARK_ERROR   NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, __LINE__, __func__, ""
+#define APXLOG_MARK_DEBUG   NULL, APXLOG_LEVEL_DEBUG, TRUE,  __FILE__, __LINE__, __func__, ""
+#define APXLOG_MARK_TRACE   NULL, APXLOG_LEVEL_TRACE, TRUE,  __FILE__, __LINE__, __func__, ""
+#define APXLOG_MARK_RAW     NULL, APXLOG_LEVEL_INFO,  FALSE, NULL, NULL, 0,
+#define APXLOG_MARK_SYSERR  NULL, APXLOG_LEVEL_ERROR, TRUE,  __FILE__, __LINE__, __func__, NULL
 
 LPWSTR apxLogFile(
     APXHANDLE hPool,
@@ -99,6 +99,7 @@ apxLogWrite(
     BOOL    bTimeStamp,
     LPCSTR  szFile,
     DWORD   dwLine,
+    LPCSTR  szFunction,
     LPCSTR  szFormat,
     ...
 );
diff --git a/src/native/windows/src/log.c b/src/native/windows/src/log.c
index e1ef8fb..17ca67f 100644
--- a/src/native/windows/src/log.c
+++ b/src/native/windows/src/log.c
@@ -311,6 +311,7 @@ apxLogWrite(
     BOOL    bTimeStamp,
     LPCSTR  szFile,
     DWORD   dwLine,
+    LPCSTR  szFunction,
     LPCSTR  szFormat,
     ...)
 {
@@ -318,7 +319,7 @@ apxLogWrite(
     CHAR    buffer[1024+32] = "";
     LPSTR   szBp;
     int     len = 0;
-    LPCSTR  f = szFile;
+    LPCSTR  file = szFile;
     CHAR    sb[SIZ_PATHLEN];
     DWORD   wr;
     DWORD   dwMessageId;
@@ -339,22 +340,22 @@ apxLogWrite(
     if (dwLevel < lf->dwLogLevel)
         return 0;
     APX_LOGENTER();
-    if (f && (lf->dwLogLevel <= APXLOG_LEVEL_DEBUG || dwLevel == APXLOG_LEVEL_ERROR)) {
-        f = (szFile + lstrlenA(szFile) - 1);
-        while(f != szFile && '\\' != *f && '/' != *f)
-            f--;
-        if(f != szFile)
-            f++;
+    if (file && (lf->dwLogLevel <= APXLOG_LEVEL_DEBUG || dwLevel == APXLOG_LEVEL_ERROR)) {
+        file = (szFile + lstrlenA(szFile) - 1);
+        while(file != szFile && '\\' != *file && '/' != *file)
+            file--;
+        if(file != szFile)
+            file++;
     }
     else
-        f = NULL;
+        file = NULL;
     szBp = buffer;
     if (!szFormat) {
         if (dwMessageId == 0) {
             lstrcpyA(szBp, "Unknown error code");
             if (dwLevel == APXLOG_LEVEL_ERROR) {
                 szBp += 18;
-                wsprintfA(szBp, " occured in (%s:%d) ", f, dwLine);
+                wsprintfA(szBp, " occured in (%s:%d) ", file, dwLine);
             }
         }
         else
@@ -389,11 +390,18 @@ apxLogWrite(
             }
             WriteFile(lf->hFile, _log_level[dwLevel],
                       lstrlenA(_log_level[dwLevel]), &wr, NULL);
-            if (f && lf->dwLogLevel <= APXLOG_LEVEL_DEBUG) {
-                wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
+
+            if (szFunction && lf->dwLogLevel <= APXLOG_LEVEL_TRACE) {
+                /* add function name in TRACE mode. */
+                wsprintfA(sb, "(%10s:%-4d:%-27s) ", file, dwLine, szFunction);
+                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+            } else if (file && lf->dwLogLevel <= APXLOG_LEVEL_DEBUG) {
+                /* add file and line in DEBUG mode. */
+                wsprintfA(sb, "(%10s:%-4d) ", file, dwLine);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
             }
 
+
             /* add thread ID to log output */
             wsprintfA(sb, "[%5d] ", GetCurrentThreadId());
             WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
@@ -423,7 +431,7 @@ apxLogWrite(
     if (szFormat && dwMessageId != 0 && dwLevel == APXLOG_LEVEL_ERROR) {
         /* Print the System error description
          */
-        apxLogWrite(hFile, dwLevel, bTimeStamp, szFile, dwLine, NULL);
+        apxLogWrite(hFile, dwLevel, bTimeStamp, szFile, dwLine, szFunction, NULL);
     }
     return len;
 }