diff --git a/README.md b/README.md index bea6a9482..59c825e45 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,4 @@ For more details see also [Docker](https://github.com/WireMock-Net/WireMock.Net- #### HTTPS / SSL More details on using HTTPS (SSL) can be found here [Wiki : HTTPS](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-(SSL)) + diff --git a/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs b/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs index fbbb9f0f0..2ff237e01 100644 --- a/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs +++ b/src/WireMock.Net.Testcontainers/WireMockContainerBuilder.cs @@ -21,7 +21,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder> _isWindowsAsLazy = new(async () => { @@ -157,7 +157,7 @@ protected override WireMockContainerBuilder Init() return builder .WithPortBinding(WireMockContainer.ContainerPort, true) .WithCommand($"--WireMockLogger {DefaultLogger}") - .WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("By Stef Heyenrath")); + .WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("WireMock.Net server running")); } /// diff --git a/src/WireMock.Net/Logging/WireMockConsoleLogger.cs b/src/WireMock.Net/Logging/WireMockConsoleLogger.cs index f798c4350..84fd4df8c 100644 --- a/src/WireMock.Net/Logging/WireMockConsoleLogger.cs +++ b/src/WireMock.Net/Logging/WireMockConsoleLogger.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json; using System; +using Newtonsoft.Json; using WireMock.Admin.Requests; namespace WireMock.Logging; @@ -10,58 +10,65 @@ namespace WireMock.Logging; /// public class WireMockConsoleLogger : IWireMockLogger { + private const string NewlineWindows = "\r\n"; + private const string NewlineUnix = "\n"; + + private readonly bool _removeNewLines; + /// /// Initializes a new instance of the class. /// - public WireMockConsoleLogger() + public WireMockConsoleLogger(bool removeNewLines = false) { + _removeNewLines = removeNewLines; + Console.OutputEncoding = System.Text.Encoding.UTF8; } - /// + /// public void Debug(string formatString, params object[] args) { - Console.WriteLine(Format("Debug", formatString, args)); + WriteLine(Format("Debug", formatString, args)); } - /// + /// public void Info(string formatString, params object[] args) { - Console.WriteLine(Format("Info", formatString, args)); + WriteLine(Format("Info", formatString, args)); } - /// + /// public void Warn(string formatString, params object[] args) { - Console.WriteLine(Format("Warn", formatString, args)); + WriteLine(Format("Warn", formatString, args)); } - /// + /// public void Error(string formatString, params object[] args) { - Console.WriteLine(Format("Error", formatString, args)); + WriteLine(Format("Error", formatString, args)); } - /// + /// public void Error(string formatString, Exception exception) { - Console.WriteLine(Format("Error", formatString, exception.Message)); + WriteLine(Format("Error", formatString, exception.Message)); if (exception is AggregateException ae) { ae.Handle(ex => { - Console.WriteLine(Format("Error", "Exception {0}", ex.Message)); + WriteLine(Format("Error", "Exception {0}", ex.Message)); return true; }); } } - /// + /// public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) { string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented); - Console.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); + WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); } private static string Format(string level, string formatString, params object[] args) @@ -70,4 +77,13 @@ private static string Format(string level, string formatString, params object[] return $"{DateTime.UtcNow} [{level}] : {message}"; } + + /// + /// Writes the specified string value, followed by the current line terminator, to the console. + /// + /// The value to write. + private void WriteLine(string value) + { + Console.WriteLine(!_removeNewLines ? value : value.Replace(NewlineWindows, string.Empty).Replace(NewlineUnix, string.Empty)); + } } \ No newline at end of file diff --git a/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs b/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs index 20c18d5f2..fb78f72b4 100644 --- a/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs +++ b/src/WireMock.Net/Settings/WireMockServerSettingsParser.cs @@ -83,10 +83,16 @@ public static bool TryParseArguments(string[] args, IDictionary? environment, [N private static void ParseLoggerSettings(WireMockServerSettings settings, IWireMockLogger? logger, SimpleSettingsParser parser) { var loggerType = parser.GetStringValue("WireMockLogger"); + var removeNewLines = parser.GetBoolValue("RemoveNewLines"); + switch (loggerType) { case nameof(WireMockConsoleLogger): - settings.Logger = new WireMockConsoleLogger(); + settings.Logger = new WireMockConsoleLogger(removeNewLines); + break; + + case "WireMockNoNewLinesConsoleLogger": + settings.Logger = new WireMockConsoleLogger(true); break; case nameof(WireMockNullLogger):