-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(#603): Add default console logger
- Loading branch information
1 parent
446f002
commit 950a3f2
Showing
32 changed files
with
96 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace DotNet.Testcontainers | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.IO; | ||
using Microsoft.Extensions.Logging; | ||
|
||
/// <summary> | ||
/// An <see cref="ILogger" /> implementation that forwards messages to the console. | ||
/// Not every test framework or environment supports this approach. | ||
/// Developers may still need to configure their own logging implementation. | ||
/// If VSTest.Console.exe loads the test adapter in a deterministic order, | ||
/// we can write our own test adapter and intercept the IMessageLogger instance: | ||
/// https://github.com/microsoft/vstest/issues/4125#issuecomment-1320880502. | ||
/// To debug the test host and runner set the environment variables VSTEST_HOST_DEBUG and VSTEST_RUNNER_DEBUG to 1. | ||
/// To enable VSTest logging set VSTEST_DIAG to 1 and VSTEST_DIAG_VERBOSITY to verbose. | ||
/// The following example contains the ITestExecutor implementations. It is important that the assembly ends with TestAdapter.dll. | ||
/// <code> | ||
/// [FileExtension(DllFileExtension)] | ||
/// [FileExtension(ExeFileExtension)] | ||
/// [DefaultExecutorUri(ExecutorUri)] | ||
/// [ExtensionUri(ExecutorUri)] | ||
/// [Category(Category)] | ||
/// internal sealed class UssDiscovery : ITestDiscoverer, ITestExecutor | ||
/// { | ||
/// private const string DllFileExtension = ".dll"; | ||
/// | ||
/// private const string ExeFileExtension = ".exe"; | ||
/// | ||
/// private const string ExecutorUri = "executor://testcontainers.org/v1"; | ||
/// | ||
/// private const string Category = "managed"; | ||
/// | ||
/// public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) | ||
/// { | ||
/// } | ||
/// | ||
/// public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) | ||
/// { | ||
/// SetLogger(frameworkHandle); | ||
/// } | ||
/// | ||
/// public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) | ||
/// { | ||
/// SetLogger(frameworkHandle); | ||
/// } | ||
/// | ||
/// public void Cancel() | ||
/// { | ||
/// } | ||
/// | ||
/// private static void SetLogger(IMessageLogger logger) | ||
/// { | ||
/// // Set the TestcontainersSettings.Logger. Use a semaphore to block the test execution until the logger is set. | ||
/// } | ||
/// } | ||
/// </code> | ||
/// </summary> | ||
internal sealed class Logger : ILogger, IDisposable | ||
{ | ||
private readonly TextWriter stderr = Console.Error; | ||
|
||
private readonly TextWriter stdout = Console.Out; | ||
|
||
private readonly Stopwatch stopwatch = Stopwatch.StartNew(); | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
{ | ||
var message = string.Format(CultureInfo.CurrentCulture, "[testcontainers.org {0:hh\\:mm\\:ss\\.ff}] {1}", this.stopwatch.Elapsed, formatter.Invoke(state, exception)); | ||
this.stdout.WriteLine(message); | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return true; | ||
} | ||
|
||
public IDisposable BeginScope<TState>(TState state) | ||
{ | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.