From d4adc9799c54b46c99a02cc2e74e62ea20f809e3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 22 Jan 2014 17:38:48 -0500 Subject: reduce size of logging messages --- .../HttpServer/HttpListenerHost.cs | 17 ++++++++------- .../HttpServer/LoggerUtils.cs | 25 +++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer') diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 54fb345eb..b4c442ec8 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -253,13 +253,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer { try { - LogHttpRequest(context, index); - var request = context.Request; + LogHttpRequest(request, index); + if (request.IsWebSocketRequest) { - ProcessWebSocketRequest(context); + await ProcessWebSocketRequest(context).ConfigureAwait(false); return; } @@ -299,7 +299,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (EnableHttpRequestLogging) { - LoggerUtils.LogResponse(_logger, context, url, endPoint, duration); + LoggerUtils.LogResponse(_logger, context.Response, url, endPoint, duration); } } catch (Exception ex) @@ -315,10 +315,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// /// Logs the HTTP request. /// - /// The CTX. - private void LogHttpRequest(HttpListenerContext ctx, int index) + /// The request. + /// The index. + private void LogHttpRequest(HttpListenerRequest request, int index) { - var endpoint = ctx.Request.LocalEndPoint; + var endpoint = request.LocalEndPoint; if (endpoint != null) { @@ -329,7 +330,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (EnableHttpRequestLogging) { - LoggerUtils.LogRequest(_logger, ctx, index); + LoggerUtils.LogRequest(_logger, request, index); } } diff --git a/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs b/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs index 8fe1297c7..cbb2c5642 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/LoggerUtils.cs @@ -8,39 +8,44 @@ namespace MediaBrowser.Server.Implementations.HttpServer { public static class LoggerUtils { - public static void LogRequest(ILogger logger, HttpListenerContext ctx, int workerIndex) + /// + /// Logs the request. + /// + /// The logger. + /// The request. + /// Index of the worker. + public static void LogRequest(ILogger logger, HttpListenerRequest request, int workerIndex) { var log = new StringBuilder(); - log.AppendLine("Url: " + ctx.Request.Url); - log.AppendLine("Headers: " + string.Join(",", ctx.Request.Headers.AllKeys.Select(k => k + "=" + ctx.Request.Headers[k]))); + log.AppendLine("Ip: " + request.RemoteEndPoint + ". Headers: " + string.Join(",", request.Headers.AllKeys.Select(k => k + "=" + request.Headers[k]))); - var type = ctx.Request.IsWebSocketRequest ? "Web Socket" : "HTTP " + ctx.Request.HttpMethod; + var type = request.IsWebSocketRequest ? "Web Socket" : "HTTP " + request.HttpMethod; - logger.LogMultiline(type + " request received on worker " + workerIndex + " from " + ctx.Request.RemoteEndPoint, LogSeverity.Debug, log); + logger.LogMultiline(type + " " + request.Url, LogSeverity.Debug, log); } /// /// Logs the response. /// /// The logger. - /// The CTX. + /// The response. /// The URL. /// The end point. /// The duration. - public static void LogResponse(ILogger logger, HttpListenerContext ctx, string url, IPEndPoint endPoint, TimeSpan duration) + public static void LogResponse(ILogger logger, HttpListenerResponse response, string url, IPEndPoint endPoint, TimeSpan duration) { - var statusCode = ctx.Response.StatusCode; + var statusCode = response.StatusCode; var log = new StringBuilder(); log.AppendLine(string.Format("Url: {0}", url)); - log.AppendLine("Headers: " + string.Join(",", ctx.Response.Headers.AllKeys.Select(k => k + "=" + ctx.Response.Headers[k]))); + log.AppendLine("Headers: " + string.Join(",", response.Headers.AllKeys.Select(k => k + "=" + response.Headers[k]))); var responseTime = string.Format(". Response time: {0} ms", duration.TotalMilliseconds); - var msg = "Response code " + statusCode + " sent to " + endPoint + responseTime; + var msg = "HTTP Response " + statusCode + " to " + endPoint + responseTime; logger.LogMultiline(msg, LogSeverity.Debug, log); } -- cgit v1.2.3