Skip to content

Commit 69bed5a

Browse files
add [coverlet] prefix to logs
1 parent 1ec4bed commit 69bed5a

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

src/coverlet.core/Coverage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void PrepareModules()
7979
continue;
8080
}
8181

82-
var instrumenter = new Instrumenter(module, _identifier, _excludeFilters, _includeFilters, excludes, _excludeAttributes, _singleHit);
82+
var instrumenter = new Instrumenter(module, _identifier, _excludeFilters, _includeFilters, excludes, _excludeAttributes, _singleHit, _logger);
8383
if (instrumenter.CanInstrument())
8484
{
8585
InstrumentationHelper.BackupOriginalModule(module, _identifier);

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using Coverlet.Core.Attributes;
99
using Coverlet.Core.Helpers;
10+
using Coverlet.Core.Logging;
1011
using Coverlet.Core.Symbols;
1112

1213
using Mono.Cecil;
@@ -25,6 +26,7 @@ internal class Instrumenter
2526
private readonly string[] _excludedAttributes;
2627
private readonly bool _singleHit;
2728
private readonly bool _isCoreLibrary;
29+
private readonly ILogger _logger;
2830
private InstrumenterResult _result;
2931
private FieldDefinition _customTrackerHitsArray;
3032
private FieldDefinition _customTrackerHitsFilePath;
@@ -35,7 +37,7 @@ internal class Instrumenter
3537
private MethodReference _customTrackerRecordHitMethod;
3638
private List<string> _asyncMachineStateMethod;
3739

38-
public Instrumenter(string module, string identifier, string[] excludeFilters, string[] includeFilters, string[] excludedFiles, string[] excludedAttributes, bool singleHit)
40+
public Instrumenter(string module, string identifier, string[] excludeFilters, string[] includeFilters, string[] excludedFiles, string[] excludedAttributes, bool singleHit, ILogger logger)
3941
{
4042
_module = module;
4143
_identifier = identifier;
@@ -44,8 +46,8 @@ public Instrumenter(string module, string identifier, string[] excludeFilters, s
4446
_excludedFiles = excludedFiles ?? Array.Empty<string>();
4547
_excludedAttributes = excludedAttributes;
4648
_singleHit = singleHit;
47-
4849
_isCoreLibrary = Path.GetFileNameWithoutExtension(_module) == "System.Private.CoreLib";
50+
_logger = logger;
4951
}
5052

5153
public bool CanInstrument() => InstrumentationHelper.HasPdb(_module);
@@ -279,7 +281,10 @@ private void InstrumentMethod(MethodDefinition method)
279281
{
280282
var sourceFile = method.DebugInformation.SequencePoints.Select(s => s.Document.Url).FirstOrDefault();
281283
if (!string.IsNullOrEmpty(sourceFile) && _excludedFiles.Contains(sourceFile))
284+
{
285+
_logger.LogInformation($"Excluded source file: '{sourceFile}'");
282286
return;
287+
}
283288

284289
var methodBody = GetMethodBody(method);
285290
if (methodBody == null)

src/coverlet.msbuild.tasks/MSBuildLogger.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ namespace Coverlet.MSbuild.Tasks
77
{
88
class MSBuildLogger : ILogger
99
{
10+
private const string LogPrefix = "[coverlet]";
11+
1012
private readonly TaskLoggingHelper _log;
1113

1214
public MSBuildLogger(TaskLoggingHelper log) => _log = log;
1315

14-
public void LogVerbose(string message) => _log.LogMessage(MessageImportance.Low, message);
16+
public void LogVerbose(string message) => _log.LogMessage(MessageImportance.Low, $"{LogPrefix}{message}");
1517

1618
// We use `MessageImportance.High` because with `MessageImportance.Normal` doesn't show anything
17-
public void LogInformation(string message)=> _log.LogMessage(MessageImportance.High, message);
19+
public void LogInformation(string message)=> _log.LogMessage(MessageImportance.High, $"{LogPrefix}{message}");
1820

19-
public void LogWarning(string message) => _log.LogWarning(message);
21+
public void LogWarning(string message) => _log.LogWarning($"{LogPrefix}{message}");
2022

21-
public void LogError(string message) => _log.LogError(message);
23+
public void LogError(string message) => _log.LogError($"{LogPrefix}{message}");
2224

23-
public void LogError(Exception exception) => _log.LogErrorFromException(exception);
25+
public void LogError(Exception exception) => _log.LogErrorFromException(exception, true);
2426
}
2527
}

test/coverlet.core.tests/CoverageTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ public void TestCoverage()
2020
File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
2121
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);
2222

23-
var logger = Mock.Of<ILogger>();
24-
2523
// TODO: Find a way to mimick hits
2624

27-
var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, string.Empty, false, logger);
25+
var coverage = new Coverage(Path.Combine(directory.FullName, Path.GetFileName(module)), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, string.Empty, false, new Mock<ILogger>().Object);
2826
coverage.PrepareModules();
2927

3028
var result = coverage.GetCoverageResult();

test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using System.IO;
33
using System.Linq;
44
using Xunit;
5-
using Coverlet.Core.Instrumentation;
5+
66
using Coverlet.Core.Samples.Tests;
7+
using Moq;
8+
using Coverlet.Core.Logging;
79

810
namespace Coverlet.Core.Instrumentation.Tests
911
{
@@ -27,7 +29,7 @@ public void TestCoreLibInstrumentation()
2729
foreach (var file in files)
2830
File.Copy(Path.Combine(OriginalFilesDir, file), Path.Combine(TestFilesDir, file), overwrite: true);
2931

30-
Instrumenter instrumenter = new Instrumenter(Path.Combine(TestFilesDir, files[0]), "_coverlet_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false);
32+
Instrumenter instrumenter = new Instrumenter(Path.Combine(TestFilesDir, files[0]), "_coverlet_instrumented", Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), false, new Mock<ILogger>().Object);
3133
Assert.True(instrumenter.CanInstrument());
3234
var result = instrumenter.Instrument();
3335
Assert.NotNull(result);
@@ -119,7 +121,7 @@ private InstrumenterTest CreateInstrumentor(bool fakeCoreLibModule = false, stri
119121
File.Copy(pdb, Path.Combine(directory.FullName, destPdb), true);
120122

121123
module = Path.Combine(directory.FullName, destModule);
122-
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), attributesToIgnore, false);
124+
Instrumenter instrumenter = new Instrumenter(module, identifier, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), attributesToIgnore, false, new Mock<ILogger>().Object);
123125
return new InstrumenterTest
124126
{
125127
Instrumenter = instrumenter,

0 commit comments

Comments
 (0)