From d4adc9799c54b46c99a02cc2e74e62ea20f809e3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 22 Jan 2014 17:38:48 -0500 Subject: [PATCH] reduce size of logging messages --- .../Playback/BaseStreamingService.cs | 1 + .../WebSocket/LogFileWebSocketListener.cs | 6 ++--- .../Logging/NlogManager.cs | 2 +- .../HttpServer/HttpListenerHost.cs | 17 +++++++------ .../HttpServer/LoggerUtils.cs | 25 +++++++++++-------- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index f872b72748..6761c272de 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1060,6 +1060,7 @@ namespace MediaBrowser.Api.Playback //state.RunTimeTicks = recording.RunTimeTicks; state.ReadInputAtNativeFramerate = recording.RecordingInfo.Status == RecordingStatus.InProgress; + state.SendInputOverStandardInput = recording.RecordingInfo.Status == RecordingStatus.InProgress; state.AudioSync = 1000; state.DeInterlace = true; } diff --git a/MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs b/MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs index eae232f110..4193cc797a 100644 --- a/MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs +++ b/MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs @@ -111,9 +111,9 @@ namespace MediaBrowser.Api.WebSocket { var line = await reader.ReadLineAsync().ConfigureAwait(false); - if (line.IndexOf(", Info,", StringComparison.OrdinalIgnoreCase) != -1 || - line.IndexOf(", Warn,", StringComparison.OrdinalIgnoreCase) != -1 || - line.IndexOf(", Error,", StringComparison.OrdinalIgnoreCase) != -1) + if (line.IndexOf("Info", StringComparison.OrdinalIgnoreCase) != -1 || + line.IndexOf("Warn", StringComparison.OrdinalIgnoreCase) != -1 || + line.IndexOf("Error", StringComparison.OrdinalIgnoreCase) != -1) { lines.Add(line); } diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index 40dc380ea8..fe530f917d 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -89,7 +89,7 @@ namespace MediaBrowser.Common.Implementations.Logging var logFile = new FileTarget { FileName = path, - Layout = "${longdate}, ${level}, ${logger}, ${message}" + Layout = "${longdate} ${level} - ${logger}: ${message}" }; RemoveTarget("ApplicationLogFile"); diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 54fb345eb4..b4c442ec8a 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 8fe1297c72..cbb2c5642d 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); }