-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2228 Create --kind and --level arguments for more granular control #2241
Conversation
@@ -267,13 +267,13 @@ internal AggregatingLogger InitializeLogger(AnalyzeOptionsBase analyzeOptions) | |||
|
|||
if (!analyzeOptions.Quiet) | |||
{ | |||
_consoleLogger = new ConsoleLogger(analyzeOptions.Verbose, _tool.Driver.Name) { CaptureOutput = _captureConsoleOutput }; | |||
_consoleLogger = new ConsoleLogger(analyzeOptions.Verbose, _tool.Driver.Name, analyzeOptions.Level, analyzeOptions.Kind) { CaptureOutput = _captureConsoleOutput }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should remove analyzeOptions.Verbose from the ConsoleLogger constructor signature, in preparation for that Verbose's eventual retirement? Instead, if verbose is passed, we could set Level and Kind to the maximum level. We do something similar with "options.ComputeFileHashes". We could also do the opposite with analyzeOptions.Quiet. #Resolved
…ogger #2228 Remove verbose and largely replace it with "quiet"
…with --quiet. Correct some tests
src/Sarif/Writers/BaseLogger.cs
Outdated
{ | ||
if (failureLevels.Contains(FailureLevel.Error)) | ||
{ | ||
throw new ArgumentException("Invalid kind & level combination"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new ArgumentException("Invalid kind & level combination"); [](start = 20, length = 64)
This validation is not correct. It's fine to configure a mixture of things. The levels are only relevant if kind == Fail.
And so your actual validation here is if Kind does not include Fail, then Level must be zero. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
private bool cacheLoggingData; | ||
private string currentFileHash; | ||
|
||
public Dictionary<string, List<Notification>> HashToNotificationsMap { get; private set; } | ||
public Dictionary<string, List<Tuple<ReportingDescriptor, Result>>> HashToResultsMap { get; private set; } | ||
|
||
public CacheByFileHashLogger(bool verbose) | ||
public CacheByFileHashLogger(IEnumerable<FailureLevel> level, IEnumerable<ResultKind> kind) : base(level, kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level [](start = 63, length = 5)
s/be plural names #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif.Writers | ||
{ | ||
public class ConsoleLogger : IAnalysisLogger | ||
public class ConsoleLogger : BaseLogger, IAnalysisLogger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConsoleLogger [](start = 17, length = 13)
Note James: our console output should emit results in an ordered and deterministic way!
#Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"level", | ||
Separator = ';', | ||
Default = new FailureLevel[] { FailureLevel.Error, FailureLevel.Warning }, | ||
HelpText = "Filter results. Valid values: None, Note, Warning, and Error.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter results. Valid values: None, Note, Warning, and Error. [](start = 24, length = 61)
"Filter output of scan results to one or more failure levels. Valid values: Error, Warning and Note." #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"kind", | ||
Separator = ';', | ||
Default = new ResultKind[] { ResultKind.Fail }, | ||
HelpText = "Filter results. Valid values: None, NotApplicable, Pass, Facil, Review, Open, and Informational")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HelpText = "Filter results. Valid values: None, NotApplicable, Pass, Facil, Review, Open, and Informational")] [](start = 12, length = 110)
"Filter output one or more result kinds. Valid values: Fail (for literal scan results), Pass, Review, Open, NotApplicable and Informational." #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ngOptions, and correct unit tests affected
…ogger #2228 Renaming, remove quiet from Logging Options
…ogger #2228 Some changes from code review
src/ReleaseHistory.md
Outdated
## **v2.4.0** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.4.0) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.4.0) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.4.0) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.4.0) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/2.4.0) | ||
* BREAKING: Entirely remove "verbose" whose fuctionality has been replaced by --level and --kind. | ||
* BREAKING: Rename "LoggingOptions" to "LogFilePersistenceOptions" | ||
* FEATURE: --quiet will now suppress all console messages except for errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add the pr number and link just like the others, pls #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/CachingLogger.cs
Outdated
|
||
public void LogMessage(bool verbose, string message) | ||
{ | ||
if (ShouldLog(notification)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (ShouldLog(notification)) [](start = 12, length = 28)
nit: just following the pattern, can u do if (!shouldLog) -> return, so all places would be the same?
Apply this for the method below #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/ConsoleLogger.cs
Outdated
{ | ||
public ConsoleLogger(bool verbose, string toolName) | ||
public ConsoleLogger(bool quietConsole, string toolName, IEnumerable<FailureLevel> level = null, IEnumerable<ResultKind> kind = null) : base(level, kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level [](start = 91, length = 5)
rename to levels and kinds, just like the other places #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/CachingLogger.cs
Outdated
{ | ||
public CachingLogger(IEnumerable<FailureLevel> level, IEnumerable<ResultKind> kind) : base(level, kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level [](start = 55, length = 5)
rename to levels and kinds #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/ConsoleLogger.cs
Outdated
@@ -238,12 +177,18 @@ public static string NormalizeMessage(string message, bool enquote) | |||
|
|||
public void LogToolNotification(Notification notification) | |||
{ | |||
WriteToConsole(notification); | |||
if (ShouldLog(notification)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShouldLog [](start = 16, length = 9)
nit: invert condition just like the other places #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -6,22 +6,20 @@ | |||
namespace Microsoft.CodeAnalysis.Sarif.Writers | |||
{ | |||
[Flags] | |||
public enum LoggingOptions | |||
public enum LogFilePersistenceOptions | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/SarifLogger.cs
Outdated
OptionallyEmittedData dataToInsert = OptionallyEmittedData.None, | ||
OptionallyEmittedData dataToRemove = OptionallyEmittedData.None, | ||
Tool tool = null, | ||
Run run = null, | ||
IEnumerable<string> analysisTargets = null, | ||
IEnumerable<string> invocationTokensToRedact = null, | ||
IEnumerable<string> invocationPropertiesToLog = null, | ||
string defaultFileEncoding = null) | ||
string defaultFileEncoding = null, | ||
IEnumerable<FailureLevel> level = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level [](start = 38, length = 5)
nit: rename to levels and kinds #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/SarifLogger.cs
Outdated
TextWriter textWriter, | ||
LogFilePersistenceOptions logFilePersistenceOptions, | ||
bool closeWriterOnDipose, | ||
IEnumerable<FailureLevel> level, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level [](start = 38, length = 5)
nit: levels and kinds #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OptionallyEmittedData dataToInsert = OptionallyEmittedData.None, | ||
OptionallyEmittedData dataToRemove = OptionallyEmittedData.None, | ||
Tool tool = null, | ||
Run run = null, | ||
IEnumerable<string> analysisTargets = null, | ||
IEnumerable<string> invocationTokensToRedact = null, | ||
IEnumerable<string> invocationPropertiesToLog = null, | ||
string defaultFileEncoding = null) | ||
string defaultFileEncoding = null, | ||
IEnumerable<FailureLevel> level = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level [](start = 38, length = 5)
nit: levels and kinds #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sarif/Writers/BaseLogger.cs
Outdated
return _failureLevels.Contains(result.Level); | ||
} | ||
|
||
return _resultKinds.Contains(result.Kind) && _failureLevels.Contains(result.Level); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return _resultKinds.Contains(result.Kind) && _failureLevels.Contains(result.Level); [](start = 12, length = 83)
If you have this check, you must always populate failure levels with 'None' to accommodate kinds, like 'Open' that never set a failure level (because a level only applies to kind 'Fail')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code would be much cleaner if you first checked the kind. And then, IFF kind == Fail, check the failure levels.
In reply to: 562957160 [](ancestors = 562957160)
src/Sarif/Writers/BaseLogger.cs
Outdated
// If resultKinds does not include "fail" then failureLevels MUST be none/zero | ||
if (!_resultKinds.Contains(ResultKind.Fail)) | ||
{ | ||
if (_failureLevels.Count > 1 || _failureLevels[0] != FailureLevel.None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_failureLevels[0] != FailureLevel.None [](start = 48, length = 38)
people should never specify None. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
namespace Microsoft.CodeAnalysis.Test.UnitTests.Sarif.Writers | ||
{ | ||
public class BaseLoggerTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BaseLoggerTests [](start = 17, length = 15)
These tests are comprehensive enough. Please add a test for this user configuration:
--kind Open;Fail --level Error
Your code currently won't work for this combination (which should allow through any Open or Fail result (but only Fail messages of level Error)
|
||
if (!succeeded) | ||
{ | ||
// TODO: This seems like uninformative error output. All these errors get squished into one generic message | ||
// whenever something goes wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File a GH issue and add the link to this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕐
* Change validation in BaseLogger and correct unit tests and code broken as a result * Correct formatting * Test SarifLogger honors Kind/Level * Refactor, remove redundant code
Fixes #2228