Skip to content
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

Merged
merged 39 commits into from
Jan 25, 2021

Conversation

jameswinkler
Copy link
Collaborator

Fixes #2228

@@ -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 };
Copy link
Collaborator Author

@jameswinkler jameswinkler Jan 14, 2021

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

{
if (failureLevels.Contains(FailureLevel.Error))
{
throw new ArgumentException("Invalid kind & level combination");
Copy link
Member

@michaelcfanning michaelcfanning Jan 18, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


In reply to: 559746343 [](ancestors = 559746343)

{
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)
Copy link
Member

@michaelcfanning michaelcfanning Jan 18, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


In reply to: 559747791 [](ancestors = 559747791)

using System.Globalization;
using System.Linq;
using System.Text;

namespace Microsoft.CodeAnalysis.Sarif.Writers
{
public class ConsoleLogger : IAnalysisLogger
public class ConsoleLogger : BaseLogger, IAnalysisLogger
Copy link
Member

@michaelcfanning michaelcfanning Jan 18, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our emails, created an issue here: #2250


In reply to: 559749330 [](ancestors = 559749330)

"level",
Separator = ';',
Default = new FailureLevel[] { FailureLevel.Error, FailureLevel.Warning },
HelpText = "Filter results. Valid values: None, Note, Warning, and Error.")]
Copy link
Member

@michaelcfanning michaelcfanning Jan 18, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 559750572 [](ancestors = 559750572)

"kind",
Separator = ';',
Default = new ResultKind[] { ResultKind.Fail },
HelpText = "Filter results. Valid values: None, NotApplicable, Pass, Facil, Review, Open, and Informational")]
Copy link
Member

@michaelcfanning michaelcfanning Jan 18, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 559751125 [](ancestors = 559751125)

@jameswinkler jameswinkler marked this pull request as ready for review January 20, 2021 18:51
## **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.
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561424247 [](ancestors = 561424247)


public void LogMessage(bool verbose, string message)
{
if (ShouldLog(notification))
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561426472 [](ancestors = 561426472)

{
public ConsoleLogger(bool verbose, string toolName)
public ConsoleLogger(bool quietConsole, string toolName, IEnumerable<FailureLevel> level = null, IEnumerable<ResultKind> kind = null) : base(level, kind)
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561427077 [](ancestors = 561427077)

{
public CachingLogger(IEnumerable<FailureLevel> level, IEnumerable<ResultKind> kind) : base(level, kind)
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561427374 [](ancestors = 561427374)

@@ -238,12 +177,18 @@ public static string NormalizeMessage(string message, bool enquote)

public void LogToolNotification(Notification notification)
{
WriteToConsole(notification);
if (ShouldLog(notification))
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561428877 [](ancestors = 561428877)

@@ -6,22 +6,20 @@
namespace Microsoft.CodeAnalysis.Sarif.Writers
{
[Flags]
public enum LoggingOptions
public enum LogFilePersistenceOptions

Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561429474 [](ancestors = 561429474)

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,
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 561430439 [](ancestors = 561430439)

Copy link
Collaborator

@eddynaka eddynaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

TextWriter textWriter,
LogFilePersistenceOptions logFilePersistenceOptions,
bool closeWriterOnDipose,
IEnumerable<FailureLevel> level,
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 562032468 [](ancestors = 562032468)

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,
Copy link
Collaborator

@eddynaka eddynaka Jan 21, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


In reply to: 562033198 [](ancestors = 562033198)

return _failureLevels.Contains(result.Level);
}

return _resultKinds.Contains(result.Kind) && _failureLevels.Contains(result.Level);
Copy link
Member

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')

Copy link
Member

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)

// 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)
Copy link
Member

@michaelcfanning michaelcfanning Jan 22, 2021

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, this is redundant but not bad input.


In reply to: 562958403 [](ancestors = 562958403)


namespace Microsoft.CodeAnalysis.Test.UnitTests.Sarif.Writers
{
public class BaseLoggerTests
Copy link
Member

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.
Copy link
Member

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.

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

jameswinkler and others added 2 commits January 25, 2021 18:45
* 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
@eddynaka eddynaka merged commit 6c931ba into main Jan 25, 2021
@eddynaka eddynaka deleted the users/ednakamu/base-logger branch January 25, 2021 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --kind and --level arguments for granular control of results reporting
3 participants