[mapguide-commits] r5011 - in branches/2.2/MgDev: Common/MapGuideCommon/System Web/src Web/src/ApacheAgent Web/src/CgiAgent Web/src/HttpHandler Web/src/IsapiAgent Web/src/MapAgentCommon Web/src/WebSupport

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Jul 8 13:02:18 EDT 2010


Author: brucedechant
Date: 2010-07-08 17:02:18 +0000 (Thu, 08 Jul 2010)
New Revision: 5011

Modified:
   branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp
   branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.h
   branches/2.2/MgDev/Web/src/ApacheAgent/ApacheAgent.cpp
   branches/2.2/MgDev/Web/src/CgiAgent/CgiAgent.cpp
   branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.cpp
   branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.h
   branches/2.2/MgDev/Web/src/IsapiAgent/IsapiAgent.cpp
   branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.cpp
   branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.h
   branches/2.2/MgDev/Web/src/WebSupport/InitializeWebTier.cpp
   branches/2.2/MgDev/Web/src/webconfig.ini
Log:
Fix for trac ticket 1337 - Web tier logging
http://trac.osgeo.org/mapguide/ticket/1337

Notes:
- Add web tier logging


Modified: branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp
===================================================================
--- branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -481,6 +481,14 @@
 const STRING MgConfigProperties::AgentDisableAuthoring                                      = L"DisableAuthoring";
 const STRING MgConfigProperties::AgentDisableWfs                                            = L"DisableWfs";
 const STRING MgConfigProperties::AgentDisableWms                                            = L"DisableWms";
+const STRING MgConfigProperties::AgentErrorLogEnabled                                       = L"ErrorLogEnabled";
+const bool   MgConfigProperties::DefaultAgentErrorLogEnabled                                = false;
+const STRING MgConfigProperties::AgentErrorLogFilename                                      = L"ErrorLogFilename";
+const STRING MgConfigProperties::DefaultAgentErrorLogFilename                               = L"Error.log";
+const STRING MgConfigProperties::AgentRequestLogEnabled                                     = L"RequestLogEnabled";
+const bool   MgConfigProperties::DefaultAgentRequestLogEnabled                              = false;
+const STRING MgConfigProperties::AgentRequestLogFilename                                    = L"RequestLogFilename";
+const STRING MgConfigProperties::DefaultAgentRequestLogFilename                             = L"Request.log";
 
 // ******************************************************************
 // OGC Properties
@@ -723,6 +731,10 @@
     { MgConfigProperties::AgentDisableAuthoring                                     , MgPropertyType::Boolean   , 0                                     , 1                                     , L""                                       },
     { MgConfigProperties::AgentDisableWfs                                           , MgPropertyType::Boolean   , 0                                     , 1                                     , L""                                       },
     { MgConfigProperties::AgentDisableWms                                           , MgPropertyType::Boolean   , 0                                     , 1                                     , L""                                       },
+    { MgConfigProperties::AgentErrorLogEnabled                                      , MgPropertyType::Boolean   , 0                                     , 1                                     , L""                                       },
+    { MgConfigProperties::AgentErrorLogFilename                                     , MgPropertyType::String    , MG_CONFIG_MIN_FILE_NAME_LENGTH        , MG_CONFIG_MAX_FILE_NAME_LENGTH        , MG_CONFIG_FILE_NAME_RESERVED_CHARACTERS   },
+    { MgConfigProperties::AgentRequestLogEnabled                                    , MgPropertyType::Boolean   , 0                                     , 1                                     , L""                                       },
+    { MgConfigProperties::AgentRequestLogFilename                                   , MgPropertyType::String    , MG_CONFIG_MIN_FILE_NAME_LENGTH        , MG_CONFIG_MAX_FILE_NAME_LENGTH        , MG_CONFIG_FILE_NAME_RESERVED_CHARACTERS   },
     { L""                                                                           , 0                         , 0.0                                   , 0.0                                   , L""                                       }
 };
 

Modified: branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.h
===================================================================
--- branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.h	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Common/MapGuideCommon/System/ConfigProperties.h	2010-07-08 17:02:18 UTC (rev 5011)
@@ -828,6 +828,22 @@
     /// Disables Http operations used for OGC Wms
     static const STRING AgentDisableWms;                                /// value("DisableWms")
 
+    /// Agent error log enabled
+    static const STRING AgentErrorLogEnabled;                           /// value("ErrorLogEnabled")
+    static const bool DefaultAgentErrorLogEnabled;                      /// value(false)
+
+    /// Agent error log filename
+    static const STRING AgentErrorLogFilename;                          /// value("ErrorLogFilename")
+    static const STRING DefaultAgentErrorLogFilename;                   /// value("Error.log")
+
+    /// Agent request log enabled
+    static const STRING AgentRequestLogEnabled;                         /// value("RequestLogEnabled")
+    static const bool DefaultAgentRequestLogEnabled;                    /// value(false)
+
+    /// Agent error log filename
+    static const STRING AgentRequestLogFilename;                        /// value("RequestLogFilename")
+    static const STRING DefaultAgentRequestLogFilename;                 /// value("Request.log")
+
     /// OGC PROPERTIES SECTION -------------------------------------------------------------------------------------------
 
     /// Ogc properties

Modified: branches/2.2/MgDev/Web/src/ApacheAgent/ApacheAgent.cpp
===================================================================
--- branches/2.2/MgDev/Web/src/ApacheAgent/ApacheAgent.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/ApacheAgent/ApacheAgent.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -155,24 +155,25 @@
 
     // check for CLIENTIP, if it's not there (and it shouldn't be),
     // add it in using httpClientIp. httpXFF or remoteAddr
+    STRING clientIp = L"";
     if (!params->ContainsParameter(L"CLIENTIP")) // NOXLATE
     {
         if (!httpClientIp.empty()
             && _stricmp(httpClientIp.c_str(), MapAgentStrings::Unknown) != 0)
         {
-            STRING wHttpClientIp = MgUtil::MultiByteToWideChar(httpClientIp);
-            params->AddParameter(L"CLIENTIP", wHttpClientIp); // NOXLATE
+            clientIp = MgUtil::MultiByteToWideChar(httpClientIp);
+            params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
         }
         else if (!httpXFF.empty()
             && _stricmp(httpXFF.c_str(), MapAgentStrings::Unknown) != 0)
         {
-            STRING wHttpXFF = MgUtil::MultiByteToWideChar(httpXFF);
-            params->AddParameter(L"CLIENTIP", wHttpXFF); // NOXLATE
+            clientIp = MgUtil::MultiByteToWideChar(httpXFF);
+            params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
         }
         else if (!remoteAddr.empty())
         {
-            STRING wRemoteAddr = MgUtil::MultiByteToWideChar(remoteAddr);
-            params->AddParameter(L"CLIENTIP", wRemoteAddr); // NOXLATE
+            clientIp = MgUtil::MultiByteToWideChar(remoteAddr);
+            params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
         }
     }
 
@@ -187,6 +188,17 @@
         gotAuth = MapAgentCommon::ParseAuth((char *)auth.c_str(), params);
     }
 
+    // Log request information
+    string postData = "";
+    if (!requestMethod.empty() && requestMethod.find("POST") != string::npos)  // NOXLATE
+    {
+        // Get the post xml data
+        postData = params->GetXmlPostData();
+    }
+
+    STRING client = params->GetParameterValue(MgHttpResourceStrings::reqClientAgent);
+    MapAgentCommon::LogRequest(client, clientIp, url, requestMethod, postData, query);
+
     Ptr<MgPropertyCollection> paramList = params->GetParameters()->GetPropertyCollection();
     if (paramList != NULL)
     {

Modified: branches/2.2/MgDev/Web/src/CgiAgent/CgiAgent.cpp
===================================================================
--- branches/2.2/MgDev/Web/src/CgiAgent/CgiAgent.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/CgiAgent/CgiAgent.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -52,6 +52,7 @@
 
 bool ParseAuth(char* AuthString, MgHttpRequestParam* params);
 bool AuthenticateOgcRequest(MgHttpRequestParam* params);
+void LogRequest(CREFSTRING client, CREFSTRING clientIp, std::string &url, std::string &requestMethod, std::string &postData, std::string &query);
 
 // Forward declare Web Tier initialization routine
 void Initialize();
@@ -165,24 +166,25 @@
 
         // check for CLIENTIP, if it's not there (and it shouldn't be),
         // add it in using httpClientIp. httpXFF or remoteAddr
+        STRING clientIp = L"";
         if (!params->ContainsParameter(L"CLIENTIP")) // NOXLATE
         {
             if (NULL != httpClientIp && strlen(httpClientIp) > 0
                 && _stricmp(httpClientIp, MapAgentStrings::Unknown) != 0)
             {
-                STRING wHttpClientIp = MgUtil::MultiByteToWideChar(httpClientIp);
-                params->AddParameter(L"CLIENTIP", wHttpClientIp); // NOXLATE
+                clientIp = MgUtil::MultiByteToWideChar(httpClientIp);
+                params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
             }
             else if (NULL != httpXFF && strlen(httpXFF) > 0
                 && _stricmp(httpXFF, MapAgentStrings::Unknown) != 0)
             {
-                STRING wHttpXFF = MgUtil::MultiByteToWideChar(httpXFF);
-                params->AddParameter(L"CLIENTIP", wHttpXFF); // NOXLATE
+                clientIp = MgUtil::MultiByteToWideChar(httpXFF);
+                params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
             }
             else if (NULL != remoteAddr && strlen(remoteAddr) > 0)
             {
-                STRING wRemoteAddr = MgUtil::MultiByteToWideChar(remoteAddr);
-                params->AddParameter(L"CLIENTIP", wRemoteAddr); // NOXLATE
+                clientIp = MgUtil::MultiByteToWideChar(remoteAddr);
+                params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
             }
         }
 
@@ -197,6 +199,19 @@
             gotAuth = ParseAuth(auth, params);
         }
 
+        // Log request information
+        string postData = "";
+        if (requestMethod && _stricmp(requestMethod, "POST") == 0)  // NOXLATE
+        {
+            // Get the post xml data
+            postData = params->GetXmlPostData();
+        }
+
+        STRING client = params->GetParameterValue(MgHttpResourceStrings::reqClientAgent);
+        string strRequestMethod= std::string(requestMethod);
+        string strQuery = std::string(query);
+        LogRequest(client, clientIp, url, strRequestMethod, postData, strQuery);
+
         Ptr<MgPropertyCollection> paramList = params->GetParameters()->GetPropertyCollection();
         if (paramList != NULL)
         {
@@ -477,3 +492,54 @@
     }
 #endif
 }
+
+void LogRequest(CREFSTRING client, CREFSTRING clientIp, std::string &url, std::string &requestMethod, std::string &postData, std::string &query)
+{
+    // Log request information
+    ACE_MT (ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, *ACE_Static_Object_Lock::instance()));
+    static INT32 requestId = 1;
+
+    MgConfiguration* cfg = MgConfiguration::GetInstance();
+
+    // Is log enabled?
+    bool bLogEnabled = false;
+    cfg->GetBoolValue(MgConfigProperties::AgentPropertiesSection, MgConfigProperties::AgentRequestLogEnabled, bLogEnabled, MgConfigProperties::DefaultAgentRequestLogEnabled);
+
+    if(bLogEnabled)
+    {
+        // Get the logs path
+        STRING path = L"";
+        cfg->GetStringValue(MgConfigProperties::GeneralPropertiesSection, MgConfigProperties::GeneralPropertyLogsPath, path, MgConfigProperties::DefaultGeneralPropertyLogsPath);
+
+        // Check if path ends with a '/' if not, add one if needed
+        MgFileUtil::AppendSlashToEndOfPath(path);
+
+        STRING filename = L"";
+        cfg->GetStringValue(MgConfigProperties::AgentPropertiesSection, MgConfigProperties::AgentRequestLogFilename, filename, MgConfigProperties::DefaultAgentRequestLogFilename);
+        filename = path + filename;
+
+        FILE* fp = ACE_OS::fopen(MG_WCHAR_TO_TCHAR(filename), ACE_TEXT("a+"));
+        if (fp)
+        {
+            MgDateTime currentTime;
+            STRING strCurrentTime = currentTime.ToXmlString(false);
+
+            ACE_OS::fprintf(fp, ACE_TEXT("<%s> %d\t%s\t%s\t%s\t%s\n"), MG_WCHAR_TO_TCHAR(strCurrentTime), requestId, MG_WCHAR_TO_TCHAR(client), MG_WCHAR_TO_TCHAR(clientIp), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(requestMethod)), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(url)));
+
+            if (!postData.empty())  // NOXLATE
+            {
+                ACE_OS::fprintf(fp, ACE_TEXT(" Postdata: %s\n"), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(postData)));
+            }
+
+            if (!query.empty())
+            {
+                ACE_OS::fprintf(fp, ACE_TEXT(" Query   : %s\n"), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(query)));
+            }
+
+            ACE_OS::fclose(fp);
+        }
+    }
+
+    // Increment the request Id
+    requestId++;
+}

Modified: branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.cpp
===================================================================
--- branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -17,3 +17,72 @@
 
 #include "HttpHandler.h"
 #include "HttpUtil.h"
+
+void MgHttpUtil::LogException(MgException* exception)
+{
+    if(NULL != exception)
+    {
+        ACE_MT (ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, *ACE_Static_Object_Lock::instance()));
+
+        MgConfiguration* cfg = MgConfiguration::GetInstance();
+
+        // Is log enabled?
+        bool bLogEnabled = false;
+        cfg->GetBoolValue(MgConfigProperties::AgentPropertiesSection, MgConfigProperties::AgentErrorLogEnabled, bLogEnabled, MgConfigProperties::DefaultAgentErrorLogEnabled);
+
+        if(bLogEnabled)
+        {
+            // Get the logs path
+            STRING path = L"";
+            cfg->GetStringValue(MgConfigProperties::GeneralPropertiesSection, MgConfigProperties::GeneralPropertyLogsPath, path, MgConfigProperties::DefaultGeneralPropertyLogsPath);
+
+            // Check if path ends with a '/' if not, add one if needed
+            MgFileUtil::AppendSlashToEndOfPath(path);
+
+            STRING filename = L"";
+            cfg->GetStringValue(MgConfigProperties::AgentPropertiesSection, MgConfigProperties::AgentErrorLogFilename, filename, MgConfigProperties::DefaultAgentErrorLogFilename);
+            filename = path + filename;
+
+            FILE* fp = ACE_OS::fopen(MG_WCHAR_TO_TCHAR(filename), ACE_TEXT("a+"));
+            if (fp)
+            {
+                MgDateTime currentTime;
+                STRING strCurrentTime = currentTime.ToXmlString(false);
+
+                STRING message = exception->GetExceptionMessage();
+                STRING stackTrace = exception->GetStackTrace();
+                ACE_OS::fprintf(fp, ACE_TEXT("<%s>\n"), MG_WCHAR_TO_TCHAR(strCurrentTime));
+                ACE_OS::fprintf(fp, ACE_TEXT(" Error: %s\n"), MG_WCHAR_TO_TCHAR(message));
+
+                // Add the stack trace
+                // Do not log empty stack traces
+                if (!stackTrace.empty())
+                {
+                    STRING entry = L"";
+                    entry += L" " + MgResources::StackTrace + L":";
+
+                    size_t size = stackTrace.size();
+
+                    if (size > 0)
+                    {
+                        STRING trace = stackTrace.c_str();
+
+                        // Get rid of extra \n at the end of the stack trace
+                        if (trace[size-1] == L'\n')
+                        {
+                            trace.erase((size-1), 1);
+                        }
+
+                        // Make it look "pretty"
+                        trace = MgUtil::ReplaceString(trace, L"\n", L"\n  ");
+                        entry += L"\n  " + trace + L"\n";
+                    }
+
+                    ACE_OS::fprintf(fp, ACE_TEXT("%s"), MG_WCHAR_TO_TCHAR(entry));
+                }
+
+                ACE_OS::fclose(fp);
+            }
+        }
+    }
+}

Modified: branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.h
===================================================================
--- branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.h	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/HttpHandler/HttpUtil.h	2010-07-08 17:02:18 UTC (rev 5011)
@@ -25,15 +25,20 @@
 
 #define MG_HTTP_HANDLER_CATCH(methodName)                                     \
     MG_CATCH(methodName)                                                      \
+    MgHttpUtil::LogException(mgException);                                    \
 
 #define MG_HTTP_HANDLER_THROW()                                               \
+    MgHttpUtil::LogException(mgException);                                    \
     MG_THROW()                                                                \
 
 #define MG_HTTP_HANDLER_CATCH_AND_THROW(methodName)                           \
-    MG_CATCH_AND_THROW(methodName)                                            \
+    MG_CATCH(methodName)                                                      \
+    MgHttpUtil::LogException(mgException);                                    \
+    MG_THROW()                                                                \
 
 #define MG_HTTP_HANDLER_CATCH_AND_THROW_EX(methodName)                        \
     MG_CATCH(methodName)                                                      \
+    MgHttpUtil::LogException(mgException);                                    \
                                                                               \
     if (mgException != NULL)                                                  \
     {                                                                         \
@@ -48,6 +53,7 @@
 
 #define MG_HTTP_HANDLER_CATCH_AND_THROW_EX2(methodName, hResult, hRequest)    \
     MG_CATCH(methodName)                                                      \
+    MgHttpUtil::LogException(mgException);                                    \
                                                                               \
     if (mgException != NULL)                                                  \
     {                                                                         \
@@ -60,4 +66,13 @@
         mgException->Raise();                                                 \
     }                                                                         \
 
+class MgHttpUtil
+{
+public:
+    MgHttpUtil();
+    ~MgHttpUtil();
+
+    static void LogException(MgException* exception);
+};
+
 #endif

Modified: branches/2.2/MgDev/Web/src/IsapiAgent/IsapiAgent.cpp
===================================================================
--- branches/2.2/MgDev/Web/src/IsapiAgent/IsapiAgent.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/IsapiAgent/IsapiAgent.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -119,24 +119,25 @@
 
     // check for CLIENTIP, if it's not there (and it shouldn't be),
     // add it in using httpClientIp. httpXFF or remoteAddr
+    STRING clientIp = L"";
     if (!params->ContainsParameter(L"CLIENTIP")) // NOXLATE
     {
         if (bHttpClientIp && NULL != httpClientIp && strlen(httpClientIp) > 0
             && _stricmp(httpClientIp, MapAgentStrings::Unknown) != 0)
         {
-            STRING wHttpClientIp = MgUtil::MultiByteToWideChar(httpClientIp);
-            params->AddParameter(L"CLIENTIP", wHttpClientIp); // NOXLATE
+            clientIp = MgUtil::MultiByteToWideChar(httpClientIp);
+            params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
         }
         else if (bHttpXFF && NULL != httpXFF && strlen(httpXFF) > 0
             && _stricmp(httpXFF, MapAgentStrings::Unknown) != 0)
         {
-            STRING wHttpXFF = MgUtil::MultiByteToWideChar(httpXFF);
-            params->AddParameter(L"CLIENTIP", wHttpXFF); // NOXLATE
+            clientIp = MgUtil::MultiByteToWideChar(httpXFF);
+            params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
         }
         else if (bRemoteAddr && NULL != remoteAddr && strlen(remoteAddr) > 0)
         {
-            STRING wRemoteAddr = MgUtil::MultiByteToWideChar(remoteAddr);
-            params->AddParameter(L"CLIENTIP", wRemoteAddr); // NOXLATE
+            clientIp = MgUtil::MultiByteToWideChar(remoteAddr);
+            params->AddParameter(L"CLIENTIP", clientIp); // NOXLATE
         }
     }
 
@@ -154,6 +155,17 @@
         gotAuth = MapAgentCommon::ParseAuth(auth, params);
     }
 
+    // Log request information
+    string postData = "";
+    if (requestMethod && _stricmp(requestMethod, "POST") == 0)  // NOXLATE
+    {
+        // Get the post xml data
+        postData = params->GetXmlPostData();
+    }
+
+    STRING client = params->GetParameterValue(MgHttpResourceStrings::reqClientAgent);
+    MapAgentCommon::LogRequest(client, clientIp, url, std::string(requestMethod), postData, std::string(query));
+
     Ptr<MgPropertyCollection> paramList = params->GetParameters()->GetPropertyCollection();
     if (paramList != NULL)
     {

Modified: branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.cpp
===================================================================
--- branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -287,3 +287,54 @@
         }
     }
 }
+
+void MapAgentCommon::LogRequest(CREFSTRING client, CREFSTRING clientIp, std::string &url, std::string &requestMethod, std::string &postData, std::string &query)
+{
+    // Log request information
+    ACE_MT (ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, *ACE_Static_Object_Lock::instance()));
+    static INT32 requestId = 1;
+
+    MgConfiguration* cfg = MgConfiguration::GetInstance();
+
+    // Is log enabled?
+    bool bLogEnabled = false;
+    cfg->GetBoolValue(MgConfigProperties::AgentPropertiesSection, MgConfigProperties::AgentRequestLogEnabled, bLogEnabled, MgConfigProperties::DefaultAgentRequestLogEnabled);
+
+    if(bLogEnabled)
+    {
+        // Get the logs path
+        STRING path = L"";
+        cfg->GetStringValue(MgConfigProperties::GeneralPropertiesSection, MgConfigProperties::GeneralPropertyLogsPath, path, MgConfigProperties::DefaultGeneralPropertyLogsPath);
+
+        // Check if path ends with a '/' if not, add one if needed
+        MgFileUtil::AppendSlashToEndOfPath(path);
+
+        STRING filename = L"";
+        cfg->GetStringValue(MgConfigProperties::AgentPropertiesSection, MgConfigProperties::AgentRequestLogFilename, filename, MgConfigProperties::DefaultAgentRequestLogFilename);
+        filename = path + filename;
+
+        FILE* fp = ACE_OS::fopen(MG_WCHAR_TO_TCHAR(filename), ACE_TEXT("a+"));
+        if (fp)
+        {
+            MgDateTime currentTime;
+            STRING strCurrentTime = currentTime.ToXmlString(false);
+
+            ACE_OS::fprintf(fp, ACE_TEXT("<%s> %d\t%s\t%s\t%s\t%s\n"), MG_WCHAR_TO_TCHAR(strCurrentTime), requestId, MG_WCHAR_TO_TCHAR(client), MG_WCHAR_TO_TCHAR(clientIp), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(requestMethod)), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(url)));
+
+            if (!postData.empty())  // NOXLATE
+            {
+                ACE_OS::fprintf(fp, ACE_TEXT(" Postdata: %s\n"), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(postData)));
+            }
+
+            if (!query.empty())
+            {
+                ACE_OS::fprintf(fp, ACE_TEXT(" Query   : %s\n"), MG_WCHAR_TO_TCHAR(MgUtil::MultiByteToWideChar(query)));
+            }
+
+            ACE_OS::fclose(fp);
+        }
+    }
+
+    // Increment the request Id
+    requestId++;
+}

Modified: branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.h
===================================================================
--- branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.h	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/MapAgentCommon/MapAgentCommon.h	2010-07-08 17:02:18 UTC (rev 5011)
@@ -37,6 +37,7 @@
         STRING& paramName, STRING& paramType, MgHttpRequestParam* params, bool& bIsFile);
 
     static void DeleteTempFiles(MgHttpRequestParam* params);
+    static void LogRequest(CREFSTRING client, CREFSTRING clientIp, std::string &url, std::string &requestMethod, std::string &postData, std::string &query);
 };
 
 #endif

Modified: branches/2.2/MgDev/Web/src/WebSupport/InitializeWebTier.cpp
===================================================================
--- branches/2.2/MgDev/Web/src/WebSupport/InitializeWebTier.cpp	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/WebSupport/InitializeWebTier.cpp	2010-07-08 17:02:18 UTC (rev 5011)
@@ -51,6 +51,16 @@
 
         resources->Initialize(resourcesPath);
         resources->LoadResources(locale);
+
+        // Get the logs path
+        STRING path = L"";
+        config->GetStringValue(MgConfigProperties::GeneralPropertiesSection, MgConfigProperties::GeneralPropertyLogsPath, path, MgConfigProperties::DefaultGeneralPropertyLogsPath);
+
+        // Check if path ends with a '/' if not, add one if needed
+        MgFileUtil::AppendSlashToEndOfPath(path);
+
+        // Try and create the directory. If it already exists this will error and not a problem
+        ACE_OS::mkdir(MG_WCHAR_TO_TCHAR(path));
     }
 
     m_bInitialized = true;

Modified: branches/2.2/MgDev/Web/src/webconfig.ini
===================================================================
--- branches/2.2/MgDev/Web/src/webconfig.ini	2010-07-08 16:32:10 UTC (rev 5010)
+++ branches/2.2/MgDev/Web/src/webconfig.ini	2010-07-08 17:02:18 UTC (rev 5011)
@@ -39,6 +39,7 @@
 #                                           case and the last 2 characters must
 #                                           be upper case.
 #
+# LogsPath                         Path where log files are stored 
 # ResourcesPath                    Path where the localization resource files are stored
 # TcpIpMtu                         The TCP/IP maximum transmission unit
 #                                       0 < Value <= 65535
@@ -55,6 +56,7 @@
 #
 # *****************************************************************************
 DefaultMessageLocale               = en
+LogsPath                           = Logs/
 ResourcesPath                      = Resources/
 TcpIpMtu                           = 1460
 TempPath                           = Temp/
@@ -142,11 +144,19 @@
 #                                       0 = false and 1 = true
 # DisableWms                       Disables OGC Wms HTTP requests
 #                                       0 = false and 1 = true
+# ErrorLogEnabled                  0 = log disabled, 1 = log enabled  
+# ErrorLogFilename                 Name of the log file  
+# RequestLogEnabled                0 = log disabled, 1 = log enabled  
+# RequestLogFilename               Name of the log file  
 # *****************************************************************************
 DebugPause                         = 0
 DisableAuthoring                   = 0
 DisableWfs                         = 0
 DisableWms                         = 0
+ErrorLogEnabled                    = 0
+ErrorLogFilename                   = Error.log
+RequestLogEnabled                  = 0
+RequestLogFilename                 = Request.log
 
 [OgcProperties]
 # *****************************************************************************



More information about the mapguide-commits mailing list