[mapguide-commits] r4821 - sandbox/adsk/2.1/Web/src/CgiAgent
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri Apr 30 19:00:25 EDT 2010
Author: brucedechant
Date: 2010-04-30 19:00:23 -0400 (Fri, 30 Apr 2010)
New Revision: 4821
Modified:
sandbox/adsk/2.1/Web/src/CgiAgent/CgiAgent.cpp
Log:
Fix for trac ticket 1337 - Web tier logging
http://trac.osgeo.org/mapguide/ticket/1337
Notes:
- Fix Linux build
Modified: sandbox/adsk/2.1/Web/src/CgiAgent/CgiAgent.cpp
===================================================================
--- sandbox/adsk/2.1/Web/src/CgiAgent/CgiAgent.cpp 2010-04-30 21:50:01 UTC (rev 4820)
+++ sandbox/adsk/2.1/Web/src/CgiAgent/CgiAgent.cpp 2010-04-30 23:00:23 UTC (rev 4821)
@@ -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();
@@ -207,7 +208,9 @@
}
STRING client = params->GetParameterValue(MgHttpResourceStrings::reqClientAgent);
- MapAgentCommon::LogRequest(client, clientIp, url, std::string(requestMethod), postData, std::string(query));
+ 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)
@@ -498,3 +501,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"), strCurrentTime.c_str(), requestId, client.c_str(), clientIp.c_str(), MgUtil::MultiByteToWideChar(requestMethod).c_str(), MgUtil::MultiByteToWideChar(url).c_str());
+
+ if (!postData.empty()) // NOXLATE
+ {
+ ACE_OS::fprintf(fp, ACE_TEXT(" Postdata: %s\n"), MgUtil::MultiByteToWideChar(postData).c_str());
+ }
+
+ if (!query.empty())
+ {
+ ACE_OS::fprintf(fp, ACE_TEXT(" Query : %s\n"), MgUtil::MultiByteToWideChar(query).c_str());
+ }
+
+ ACE_OS::fclose(fp);
+ }
+ }
+
+ // Increment the request Id
+ requestId++;
+}
More information about the mapguide-commits
mailing list