Prepend process name to the log's filename.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 3 Sep 2009 10:21:09 +0000 (11:21 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 3 Sep 2009 10:21:09 +0000 (11:21 +0100)
log.cpp

diff --git a/log.cpp b/log.cpp
index 433368f..7e21970 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -63,13 +63,25 @@ static void _Open(const char *szName, const char *szExtension) {
     
     static unsigned dwCounter = 0;
 
+    char szProcessPath[PATH_MAX];
+    char *lpProcessName;
+    char *lpProcessExt;
+
+    GetModuleFileNameA(NULL, szProcessPath, sizeof(szProcessPath)/sizeof(szProcessPath[0]));
+
+    lpProcessName = strrchr(szProcessPath, '\\');
+    lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;
+    lpProcessExt = strrchr(lpProcessName, '.');
+    if(lpProcessExt)
+       *lpProcessExt = '\0';
+
     for(;;) {
         FILE *file;
         
         if(dwCounter)
-            snprintf(g_szFileName, PATH_MAX, "%s.%u.%s.gz", szName, dwCounter, szExtension);
+            snprintf(g_szFileName, PATH_MAX, "%s.%s.%u.%s.gz", lpProcessName, szName, dwCounter, szExtension);
         else
-            snprintf(g_szFileName, PATH_MAX, "%s.%s.gz", szName, szExtension);
+            snprintf(g_szFileName, PATH_MAX, "%s.%s.%s.gz", lpProcessName, szName, szExtension);
         
         file = fopen(g_szFileName, "rb");
         if(file == NULL)