diff --git a/dev-proxy-abstractions/IProxyConfiguration.cs b/dev-proxy-abstractions/IProxyConfiguration.cs index 171414fe..cbb47343 100644 --- a/dev-proxy-abstractions/IProxyConfiguration.cs +++ b/dev-proxy-abstractions/IProxyConfiguration.cs @@ -20,4 +20,5 @@ public interface IProxyConfiguration bool Record { get; } IEnumerable WatchPids { get; } IEnumerable WatchProcessNames { get; } + bool ShowTimestamps { get; } } \ No newline at end of file diff --git a/dev-proxy-abstractions/IProxyLogger.cs b/dev-proxy-abstractions/IProxyLogger.cs index 5b310652..44e1d5f8 100644 --- a/dev-proxy-abstractions/IProxyLogger.cs +++ b/dev-proxy-abstractions/IProxyLogger.cs @@ -18,7 +18,8 @@ public enum MessageType InterceptedResponse, FinishedProcessingRequest, Skipped, - Processed + Processed, + Timestamp } public class LoggingContext(SessionEventArgs session) diff --git a/dev-proxy/Logging/ProxyConsoleFormatter.cs b/dev-proxy/Logging/ProxyConsoleFormatter.cs index 43091bb5..4e05ce82 100644 --- a/dev-proxy/Logging/ProxyConsoleFormatter.cs +++ b/dev-proxy/Logging/ProxyConsoleFormatter.cs @@ -48,7 +48,9 @@ private void LogRequest(RequestLog requestLog, string category, IExternalScopePr // don't log intercepted response to console if (messageType == MessageType.InterceptedResponse || - (messageType == MessageType.Skipped && !_options.ShowSkipMessages)) + (messageType == MessageType.Skipped && !_options.ShowSkipMessages) || + (messageType == MessageType.Timestamp && !_options.ShowTimestamps) + ) { return; } @@ -238,6 +240,7 @@ private static string GetMessageTypeString(MessageType messageType) MessageType.Tip => "tip", MessageType.Skipped => "skip", MessageType.Processed => "proc", + MessageType.Timestamp => "time", _ => " " }; } @@ -258,6 +261,7 @@ private static (ConsoleColor bg, ConsoleColor fg) GetMessageTypeColor(MessageTyp MessageType.Mocked => (ConsoleColor.DarkMagenta, fgColor), MessageType.Failed => (ConsoleColor.DarkRed, fgColor), MessageType.Tip => (ConsoleColor.DarkBlue, fgColor), + MessageType.Timestamp => (bgColor, ConsoleColor.Gray), _ => (bgColor, fgColor) }; } diff --git a/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs b/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs index 066c83a5..798a5171 100644 --- a/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs +++ b/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs @@ -8,4 +8,6 @@ namespace Microsoft.DevProxy.Logging; public class ProxyConsoleFormatterOptions: ConsoleFormatterOptions { public bool ShowSkipMessages { get; set; } = true; + + public bool ShowTimestamps { get; set; } = true; } \ No newline at end of file diff --git a/dev-proxy/Program.cs b/dev-proxy/Program.cs index 07e3b964..1b8dfa61 100644 --- a/dev-proxy/Program.cs +++ b/dev-proxy/Program.cs @@ -26,6 +26,7 @@ { options.IncludeScopes = true; options.ShowSkipMessages = ProxyCommandHandler.Configuration.ShowSkipMessages; + options.ShowTimestamps = ProxyCommandHandler.Configuration.ShowTimestamps; }) .AddRequestLogger(pluginEvents) .SetMinimumLevel(ProxyHost.LogLevel ?? ProxyCommandHandler.Configuration.LogLevel); diff --git a/dev-proxy/ProxyConfiguration.cs b/dev-proxy/ProxyConfiguration.cs index f72c2c64..b5d83018 100755 --- a/dev-proxy/ProxyConfiguration.cs +++ b/dev-proxy/ProxyConfiguration.cs @@ -38,4 +38,5 @@ public class ProxyConfiguration : IProxyConfiguration public MockRequestHeader[]? FilterByHeaders { get; set; } public int ApiPort { get; set; } = 8897; public bool ShowSkipMessages { get; set; } = true; + public bool ShowTimestamps { get; set; } = true; } diff --git a/dev-proxy/ProxyEngine.cs b/dev-proxy/ProxyEngine.cs index 4dc91826..f3d01b32 100755 --- a/dev-proxy/ProxyEngine.cs +++ b/dev-proxy/ProxyEngine.cs @@ -478,7 +478,11 @@ async Task OnRequestAsync(object sender, SessionEventArgs e) using var scope = _logger.BeginScope(e.HttpClient.Request.Method ?? "", e.HttpClient.Request.Url, e.GetHashCode()); e.UserData = e.HttpClient.Request; + _logger.LogRequest($"{e.HttpClient.Request.Method} {e.HttpClient.Request.Url}", MessageType.InterceptedRequest, new LoggingContext(e)); + + _logger.LogRequest($"{DateTimeOffset.UtcNow}", MessageType.Timestamp, new LoggingContext(e)); + await HandleRequestAsync(e, proxyRequestArgs); } } diff --git a/dev-proxy/devproxyrc.json b/dev-proxy/devproxyrc.json index 1e5fadde..95c83776 100644 --- a/dev-proxy/devproxyrc.json +++ b/dev-proxy/devproxyrc.json @@ -22,5 +22,6 @@ "rate": 50, "logLevel": "information", "newVersionNotification": "stable", - "showSkipMessages": true + "showSkipMessages": true, + "showTimestamps": true } \ No newline at end of file diff --git a/schemas/v0.24.0/rc.schema.json b/schemas/v0.24.0/rc.schema.json index 38af44ae..f3c0e259 100644 --- a/schemas/v0.24.0/rc.schema.json +++ b/schemas/v0.24.0/rc.schema.json @@ -5,7 +5,7 @@ "type": "object", "properties": { "$schema": { - "type":"string" + "type": "string" }, "apiPort": { "type": "number", @@ -101,6 +101,9 @@ "items": { "type": "string" } + }, + "showTimestamps": { + "type": "boolean" } }, "required": [