From 387a1bb283c0c55178421f2c28b0d28a24dac7a1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 20 Sep 2012 22:36:47 +0100 Subject: Add ability to turn on/off logging of outgoing HTTP requests flowing through WebUtil. This is for debugging purposes. This is controlled via the "debug http" command which can already log incoming requests. This now gains a mandatory parameter of in, out or all to control what is logged. Log messages are also shortened and labelled and HTTP IN or HTTP OUT to be consistent with existing UDP PACKET IN and PACKET OUT messages. --- OpenSim/Framework/WebUtil.cs | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'OpenSim/Framework/WebUtil.cs') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 2aa4af5..7c4e852 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -54,6 +54,14 @@ namespace OpenSim.Framework MethodBase.GetCurrentMethod().DeclaringType); /// + /// Control the printing of certain debug messages. + /// + /// + /// If DebugLevel >= 3 then short notices about outgoing HTTP requests are logged. + /// + public static int DebugLevel { get; set; } + + /// /// Request number for diagnostic purposes. /// public static int RequestNumber = 0; @@ -146,7 +154,11 @@ namespace OpenSim.Framework private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed) { int reqnum = RequestNumber++; - // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); + + if (DebugLevel >= 3) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} ServiceOSD {1} {2} (timeout {3}, compressed {4})", + reqnum, method, url, timeout, compressed); string errorMessage = "unknown error"; int tickstart = Util.EnvironmentTickCount(); @@ -317,7 +329,11 @@ namespace OpenSim.Framework { int reqnum = RequestNumber++; string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown"; - // m_log.DebugFormat("[WEB UTIL]: <{0}> start form request for {1}, method {2}",reqnum,url,method); + + if (DebugLevel >= 3) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} ServiceForm {1} {2} (timeout {3})", + reqnum, method, url, timeout); string errorMessage = "unknown error"; int tickstart = Util.EnvironmentTickCount(); @@ -643,7 +659,6 @@ namespace OpenSim.Framework /// public static string[] GetPreferredImageTypes(string accept) { - if (accept == null || accept == string.Empty) return new string[0]; @@ -695,13 +710,15 @@ namespace OpenSim.Framework string requestUrl, TRequest obj, Action action) { int reqnum = WebUtil.RequestNumber++; - // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); + + if (WebUtil.DebugLevel >= 3) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} AsynchronousRequestObject {1} {2}", + reqnum, verb, requestUrl); int tickstart = Util.EnvironmentTickCount(); int tickdata = 0; - // m_log.DebugFormat("[ASYNC REQUEST]: Starting {0} {1}", verb, requestUrl); - Type type = typeof(TRequest); WebRequest request = WebRequest.Create(requestUrl); @@ -882,7 +899,11 @@ namespace OpenSim.Framework public static string MakeRequest(string verb, string requestUrl, string obj) { int reqnum = WebUtil.RequestNumber++; - // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); + + if (WebUtil.DebugLevel >= 3) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} SynchronousRestForms {1} {2}", + reqnum, verb, requestUrl); int tickstart = Util.EnvironmentTickCount(); int tickdata = 0; @@ -998,7 +1019,11 @@ namespace OpenSim.Framework public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { int reqnum = WebUtil.RequestNumber++; - // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); + + if (WebUtil.DebugLevel >= 3) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} SynchronousRestObject {1} {2}", + reqnum, verb, requestUrl); int tickstart = Util.EnvironmentTickCount(); int tickdata = 0; -- cgit v1.1 From a5b3989e5db0a3b22e44b84412227a8e487bcef2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 20 Sep 2012 23:18:19 +0100 Subject: Insert a new log level 4 for HTTP IN and HTTP OUT that will log how long the request took. This is only printed if debug http level >= 4 and the request didn't take more than the time considered 'long', in which case the existing log message is printed. This displaces the previous log levels 4 and 5 which are now 5 and 6 respectively. --- OpenSim/Framework/WebUtil.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'OpenSim/Framework/WebUtil.cs') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 7c4e852..64d61f1 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -250,6 +250,10 @@ namespace OpenSim.Framework strBuffer != null ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) : ""); + else if (DebugLevel >= 4) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} took {1}ms, {2}ms writing", + reqnum, tickdiff, tickdata); } m_log.DebugFormat( @@ -405,6 +409,10 @@ namespace OpenSim.Framework queryString != null ? (queryString.Length > MaxRequestDiagLength) ? queryString.Remove(MaxRequestDiagLength) : queryString : ""); + else if (DebugLevel >= 4) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} took {1}ms, {2}ms writing", + reqnum, tickdiff, tickdata); } m_log.WarnFormat("[SERVICE FORM]: <{0}> form request to {1} failed: {2}", reqnum, url, errorMessage); @@ -879,6 +887,12 @@ namespace OpenSim.Framework tickdata, originalRequest); } + else if (WebUtil.DebugLevel >= 4) + { + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} took {1}ms, {2}ms writing", + reqnum, tickdiff, tickdata); + } } } @@ -995,6 +1009,10 @@ namespace OpenSim.Framework tickdiff, tickdata, obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj); + else if (WebUtil.DebugLevel >= 4) + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} took {1}ms, {2}ms writing", + reqnum, tickdiff, tickdata); return respstring; } @@ -1144,6 +1162,12 @@ namespace OpenSim.Framework tickdata, originalRequest); } + else if (WebUtil.DebugLevel >= 4) + { + m_log.DebugFormat( + "[WEB UTIL]: HTTP OUT {0} took {1}ms, {2}ms writing", + reqnum, tickdiff, tickdata); + } return deserial; } -- cgit v1.1