mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-25 06:16:37 +01:00
Simplified logging of xml-rpc requests and responses.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
9ccbf35224
commit
d134317463
@ -117,7 +117,6 @@ namespace XenAPI
|
|||||||
|
|
||||||
private void LogRequest(object o, XmlRpcRequestEventArgs args)
|
private void LogRequest(object o, XmlRpcRequestEventArgs args)
|
||||||
{
|
{
|
||||||
Level logLevel;
|
|
||||||
string xml = DumpStream(args.RequestStream, String.Empty);
|
string xml = DumpStream(args.RequestStream, String.Empty);
|
||||||
|
|
||||||
// Find the method name within the XML
|
// Find the method name within the XML
|
||||||
@ -125,30 +124,32 @@ namespace XenAPI
|
|||||||
int methodNameStart = xml.IndexOf("<methodName>");
|
int methodNameStart = xml.IndexOf("<methodName>");
|
||||||
if (methodNameStart >= 0)
|
if (methodNameStart >= 0)
|
||||||
{
|
{
|
||||||
methodNameStart += 12; // skip past "<methodName>"
|
methodNameStart += 12; // skip past "<methodName>"
|
||||||
int methodNameEnd = xml.IndexOf('<', methodNameStart);
|
int methodNameEnd = xml.IndexOf('<', methodNameStart);
|
||||||
if (methodNameEnd > methodNameStart)
|
if (methodNameEnd > methodNameStart)
|
||||||
methodName = xml.Substring(methodNameStart, methodNameEnd - methodNameStart);
|
methodName = xml.Substring(methodNameStart, methodNameEnd - methodNameStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CacheWarming)
|
// do not log while downloading objects
|
||||||
logLevel = Level.Debug;
|
// also exclude calls occurring frequently; we don't need to know about them;
|
||||||
else if (methodName == "event.next" || methodName == "event.from" || methodName == "host.get_servertime" || methodName.StartsWith("task.get_")) // these occur frequently and we don't need to know about them
|
// only log the full XML at Debug level because it may have sensitive data in: CA-80174
|
||||||
logLevel = Level.Debug;
|
|
||||||
else
|
|
||||||
logLevel = Level.Info;
|
|
||||||
|
|
||||||
// Only log the full XML at Debug level because it may have sensitive data in: CA-80174
|
if (CacheWarming ||
|
||||||
if (logLevel == Level.Debug)
|
methodName == "event.next" || methodName == "event.from" || methodName == "host.get_servertime" ||
|
||||||
LogMsg(logLevel, "Invoking XML-RPC method " + methodName + ": " + xml);
|
methodName.StartsWith("task.get_"))
|
||||||
|
{
|
||||||
|
log.DebugFormat("Invoking XML-RPC method {0}: {1}", methodName, xml);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
LogMsg(logLevel, "Invoking XML-RPC method " + methodName);
|
{
|
||||||
|
log.InfoFormat("Invoking XML-RPC method {0}", methodName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogResponse(object o, XmlRpcResponseEventArgs args)
|
private void LogResponse(object o, XmlRpcResponseEventArgs args)
|
||||||
{
|
{
|
||||||
if(log.IsDebugEnabled)
|
if(log.IsDebugEnabled)
|
||||||
LogMsg(Level.Debug, DumpStream(args.ResponseStream, "XML-RPC response: "));
|
log.DebugFormat(DumpStream(args.ResponseStream, "XML-RPC response: "));
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DumpStream(Stream s, string header)
|
private string DumpStream(Stream s, string header)
|
||||||
@ -166,21 +167,11 @@ namespace XenAPI
|
|||||||
}
|
}
|
||||||
catch(OutOfMemoryException ex)
|
catch(OutOfMemoryException ex)
|
||||||
{
|
{
|
||||||
LogMsg(Level.Debug, "Session ran out of memory while trying to log the XML response stream: " + ex.Message);
|
log.DebugFormat("Session ran out of memory while trying to log the XML response stream: {0}", ex.Message);
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogMsg(Level logLevel, String msg)
|
|
||||||
{
|
|
||||||
if (logLevel == Level.Debug)
|
|
||||||
log.Debug(msg);
|
|
||||||
else if (logLevel == Level.Info)
|
|
||||||
log.Info(msg);
|
|
||||||
else
|
|
||||||
System.Diagnostics.Trace.Assert(false, "Missing log level");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The i18n'd string for the 'Logged in as:' username (AD or local root).
|
/// The i18n'd string for the 'Logged in as:' username (AD or local root).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user