reduce size of logging messages

pull/702/head
Luke Pulverenti 11 years ago
parent ac80f22686
commit d4adc9799c

@ -1060,6 +1060,7 @@ namespace MediaBrowser.Api.Playback
//state.RunTimeTicks = recording.RunTimeTicks; //state.RunTimeTicks = recording.RunTimeTicks;
state.ReadInputAtNativeFramerate = recording.RecordingInfo.Status == RecordingStatus.InProgress; state.ReadInputAtNativeFramerate = recording.RecordingInfo.Status == RecordingStatus.InProgress;
state.SendInputOverStandardInput = recording.RecordingInfo.Status == RecordingStatus.InProgress;
state.AudioSync = 1000; state.AudioSync = 1000;
state.DeInterlace = true; state.DeInterlace = true;
} }

@ -111,9 +111,9 @@ namespace MediaBrowser.Api.WebSocket
{ {
var line = await reader.ReadLineAsync().ConfigureAwait(false); var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line.IndexOf(", Info,", StringComparison.OrdinalIgnoreCase) != -1 || if (line.IndexOf("Info", StringComparison.OrdinalIgnoreCase) != -1 ||
line.IndexOf(", Warn,", StringComparison.OrdinalIgnoreCase) != -1 || line.IndexOf("Warn", StringComparison.OrdinalIgnoreCase) != -1 ||
line.IndexOf(", Error,", StringComparison.OrdinalIgnoreCase) != -1) line.IndexOf("Error", StringComparison.OrdinalIgnoreCase) != -1)
{ {
lines.Add(line); lines.Add(line);
} }

@ -89,7 +89,7 @@ namespace MediaBrowser.Common.Implementations.Logging
var logFile = new FileTarget var logFile = new FileTarget
{ {
FileName = path, FileName = path,
Layout = "${longdate}, ${level}, ${logger}, ${message}" Layout = "${longdate} ${level} - ${logger}: ${message}"
}; };
RemoveTarget("ApplicationLogFile"); RemoveTarget("ApplicationLogFile");

@ -253,13 +253,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{ {
try try
{ {
LogHttpRequest(context, index);
var request = context.Request; var request = context.Request;
LogHttpRequest(request, index);
if (request.IsWebSocketRequest) if (request.IsWebSocketRequest)
{ {
ProcessWebSocketRequest(context); await ProcessWebSocketRequest(context).ConfigureAwait(false);
return; return;
} }
@ -299,7 +299,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
if (EnableHttpRequestLogging) if (EnableHttpRequestLogging)
{ {
LoggerUtils.LogResponse(_logger, context, url, endPoint, duration); LoggerUtils.LogResponse(_logger, context.Response, url, endPoint, duration);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -315,10 +315,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <summary> /// <summary>
/// Logs the HTTP request. /// Logs the HTTP request.
/// </summary> /// </summary>
/// <param name="ctx">The CTX.</param> /// <param name="request">The request.</param>
private void LogHttpRequest(HttpListenerContext ctx, int index) /// <param name="index">The index.</param>
private void LogHttpRequest(HttpListenerRequest request, int index)
{ {
var endpoint = ctx.Request.LocalEndPoint; var endpoint = request.LocalEndPoint;
if (endpoint != null) if (endpoint != null)
{ {
@ -329,7 +330,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
if (EnableHttpRequestLogging) if (EnableHttpRequestLogging)
{ {
LoggerUtils.LogRequest(_logger, ctx, index); LoggerUtils.LogRequest(_logger, request, index);
} }
} }

@ -8,39 +8,44 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{ {
public static class LoggerUtils public static class LoggerUtils
{ {
public static void LogRequest(ILogger logger, HttpListenerContext ctx, int workerIndex) /// <summary>
/// Logs the request.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="request">The request.</param>
/// <param name="workerIndex">Index of the worker.</param>
public static void LogRequest(ILogger logger, HttpListenerRequest request, int workerIndex)
{ {
var log = new StringBuilder(); var log = new StringBuilder();
log.AppendLine("Url: " + ctx.Request.Url); log.AppendLine("Ip: " + request.RemoteEndPoint + ". Headers: " + string.Join(",", request.Headers.AllKeys.Select(k => k + "=" + request.Headers[k])));
log.AppendLine("Headers: " + string.Join(",", ctx.Request.Headers.AllKeys.Select(k => k + "=" + ctx.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);
} }
/// <summary> /// <summary>
/// Logs the response. /// Logs the response.
/// </summary> /// </summary>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="ctx">The CTX.</param> /// <param name="response">The response.</param>
/// <param name="url">The URL.</param> /// <param name="url">The URL.</param>
/// <param name="endPoint">The end point.</param> /// <param name="endPoint">The end point.</param>
/// <param name="duration">The duration.</param> /// <param name="duration">The duration.</param>
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(); var log = new StringBuilder();
log.AppendLine(string.Format("Url: {0}", url)); 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 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); logger.LogMultiline(msg, LogSeverity.Debug, log);
} }

Loading…
Cancel
Save