-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from derhally/master
Added logging to Coverage to help with debugging
- Loading branch information
Showing
8 changed files
with
110 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
using System; | ||
using Coverlet.Core.Logging; | ||
using static System.Console; | ||
|
||
namespace Coverlet.Console.Logging | ||
{ | ||
class ConsoleLogger : ILogger | ||
{ | ||
public void LogError(string message) | ||
{ | ||
ForegroundColor = ConsoleColor.Red; | ||
WriteLine(message); | ||
ForegroundColor = ConsoleColor.White; | ||
} | ||
private static readonly object _sync = new object(); | ||
|
||
public void LogInformation(string message) | ||
{ | ||
WriteLine(message); | ||
} | ||
public void LogError(string message) => Log(message, ConsoleColor.Red); | ||
|
||
public void LogSuccess(string message) | ||
{ | ||
ForegroundColor = ConsoleColor.Green; | ||
WriteLine(message); | ||
ForegroundColor = ConsoleColor.White; | ||
} | ||
public void LogError(Exception exception) => LogError(exception.ToString()); | ||
|
||
public void LogVerbose(string message) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
public void LogInformation(string message) => Log(message, ForegroundColor); | ||
|
||
public void LogVerbose(string message) => throw new NotImplementedException(); | ||
|
||
public void LogWarning(string message) => Log(message, ConsoleColor.Yellow); | ||
|
||
public void LogWarning(string message) | ||
private void Log(string message, ConsoleColor color) | ||
{ | ||
ForegroundColor = ConsoleColor.Yellow; | ||
WriteLine(message); | ||
ForegroundColor = ConsoleColor.White; | ||
lock (_sync) | ||
{ | ||
ConsoleColor currentForegroundColor; | ||
if (color != (currentForegroundColor = ForegroundColor)) | ||
{ | ||
ForegroundColor = color; | ||
WriteLine(message); | ||
ForegroundColor = currentForegroundColor; | ||
} | ||
else | ||
{ | ||
WriteLine(message); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
8 changes: 5 additions & 3 deletions
8
src/coverlet.console/Logging/ILogger.cs → src/coverlet.core/Logging/ILogger.cs
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
namespace Coverlet.Console.Logging | ||
using System; | ||
|
||
namespace Coverlet.Core.Logging | ||
{ | ||
interface ILogger | ||
public interface ILogger | ||
{ | ||
void LogSuccess(string message); | ||
void LogVerbose(string message); | ||
void LogInformation(string message); | ||
void LogWarning(string message); | ||
void LogError(string message); | ||
void LogError(Exception exception); | ||
} | ||
} |
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,25 @@ | ||
using System; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using ILogger = Coverlet.Core.Logging.ILogger; | ||
|
||
namespace Coverlet.MSbuild.Tasks | ||
{ | ||
class MSBuildLogger : ILogger | ||
{ | ||
private readonly TaskLoggingHelper _log; | ||
|
||
public MSBuildLogger(TaskLoggingHelper log) => _log = log; | ||
|
||
public void LogVerbose(string message) => _log.LogMessage(MessageImportance.Low, message); | ||
|
||
// We use `MessageImportance.High` because with `MessageImportance.Normal` doesn't show anything | ||
public void LogInformation(string message)=> _log.LogMessage(MessageImportance.High, message); | ||
|
||
public void LogWarning(string message) => _log.LogWarning(message); | ||
|
||
public void LogError(string message) => _log.LogError(message); | ||
|
||
public void LogError(Exception exception) => _log.LogErrorFromException(exception); | ||
} | ||
} |
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