From 47b6e78790be5a4b7d8a0f4c860f1e2f6f87b137 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 12 Jun 2013 21:34:20 +0100 Subject: Implement logging of first 80 characters (debug level 5) or full body data (debug level 6) on outgoing requests, depending on debug level This is set via "debug http out " This matches the existing debug level behaviours for logging incoming http data --- OpenSim/Framework/WebUtil.cs | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/WebUtil.cs') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 701fbb0..4599f62 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -151,6 +151,39 @@ namespace OpenSim.Framework } } + public static void LogOutgoingDetail(Stream outputStream) + { + using (StreamReader reader = new StreamReader(Util.Copy(outputStream), Encoding.UTF8)) + { + string output; + + if (DebugLevel == 5) + { + const int sampleLength = 80; + char[] sampleChars = new char[sampleLength]; + reader.Read(sampleChars, 0, sampleLength); + output = new string(sampleChars); + } + else + { + output = reader.ReadToEnd(); + } + + LogOutgoingDetail(output); + } + } + + public static void LogOutgoingDetail(string output) + { + if (DebugLevel == 5) + { + output = output.Substring(0, 80); + output = output + "..."; + } + + m_log.DebugFormat("[WEB UTIL]: {0}", output.Replace("\n", @"\n")); + } + private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed) { int reqnum = RequestNumber++; @@ -178,7 +211,11 @@ namespace OpenSim.Framework // If there is some input, write it into the request if (data != null) { - strBuffer = OSDParser.SerializeJsonString(data); + strBuffer = OSDParser.SerializeJsonString(data); + + if (DebugLevel >= 5) + LogOutgoingDetail(strBuffer); + byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); if (compressed) @@ -357,6 +394,10 @@ namespace OpenSim.Framework if (data != null) { queryString = BuildQueryString(data); + + if (DebugLevel >= 5) + LogOutgoingDetail(queryString); + byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString); request.ContentLength = buffer.Length; @@ -767,6 +808,9 @@ namespace OpenSim.Framework int length = (int)buffer.Length; request.ContentLength = length; + if (WebUtil.DebugLevel >= 5) + WebUtil.LogOutgoingDetail(buffer); + request.BeginGetRequestStream(delegate(IAsyncResult res) { Stream requestStream = request.EndGetRequestStream(res); @@ -954,6 +998,9 @@ namespace OpenSim.Framework length = (int)obj.Length; request.ContentLength = length; + if (WebUtil.DebugLevel >= 5) + WebUtil.LogOutgoingDetail(buffer); + Stream requestStream = null; try { @@ -1096,6 +1143,9 @@ namespace OpenSim.Framework int length = (int)buffer.Length; request.ContentLength = length; + if (WebUtil.DebugLevel >= 5) + WebUtil.LogOutgoingDetail(buffer); + Stream requestStream = null; try { @@ -1198,4 +1248,4 @@ namespace OpenSim.Framework return deserial; } } -} +} \ No newline at end of file -- cgit v1.1