-
Notifications
You must be signed in to change notification settings - Fork 323
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
Adding trace level in diag argument #1681
Conversation
if (string.IsNullOrWhiteSpace(argument)) | ||
{ | ||
throw new CommandLineException(CommandLineResources.EnableDiagUsage); | ||
HandleInvalidDiagArgument(); |
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 Exception here itself
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.
done.
/// <returns>Diag argument list.</returns> | ||
private string[] GetDiagArgumentList(string argument) | ||
{ | ||
var argumentSeperator = new char[] { ';' }; |
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.
Refactor / Reuse from Collect/Logger processors.
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.
done
@@ -228,7 +230,8 @@ private static void InitializeEqtTrace(IDictionary<string, string> argsDictionar | |||
// Setup logging if enabled | |||
if (argsDictionary.TryGetValue(LogFileArgument, out string logFile)) | |||
{ | |||
EqtTrace.InitializeVerboseTrace(logFile); | |||
var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); |
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.
verify for invalid tracelevel values,
Also verify vstest.console with older testhost
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.
Added check for invalid tracelevel values
Verified with older testhost as well.
/// <summary> | ||
/// Trace level for logs. | ||
/// </summary> | ||
public PlatformTraceLevel TraceLevel { get; set; } = PlatformTraceLevel.Verbose; |
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.
Should I use System.Diagnostics.TraceLevel here OR Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformTraceLevel.
Internally we use PlatformTraceLevel wherever TraceLevel is not present. Example: NETSTANDARD1_4
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.
PlatformTraceLevel is in PlatformAbstraction, this will mandate translationlayer users to have a reference to PlatformAbstraction as well.
If possible we should remove all the usage for System.Diagnostics.TraceLevel, rather have another TraceLevel enum in OM for this.
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.
Removed dependency on platform abstractions.
Cant remove System.Diagnostics.TraceLevel as used by exe config trace level.
var diagArgumentList = GetDiagArgumentList(argument); | ||
|
||
// Get diag file path. | ||
// Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon]. |
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.
What is the behavior in that case, do we throw an error to the user ?
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.
Yes we throw error to the user outputing diag arg usage.
/// <summary> | ||
/// Trace level for logs. | ||
/// </summary> | ||
public PlatformTraceLevel TraceLevel { get; set; } = PlatformTraceLevel.Verbose; |
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.
PlatformTraceLevel is in PlatformAbstraction, this will mandate translationlayer users to have a reference to PlatformAbstraction as well.
If possible we should remove all the usage for System.Diagnostics.TraceLevel, rather have another TraceLevel enum in OM for this.
var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); | ||
|
||
// In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose. | ||
var traceLevel = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt) ? |
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 is unexpected, I know it is a bit tricky, can we log a warning for this ?
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.
done
var diagArgumentList = ArgumemtProcessorUtilities.GetArgumentList(argument, ArgumemtProcessorUtilities.SemiColonArgumentSeperator, CommandLineResources.EnableDiagUsage); | ||
|
||
// Get diag file path. | ||
// Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon]. |
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.
Warning for case file path contains ";" ?
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.
We cant know if the semi colon is present in file path. we simply split the argument based on semi colon and the first argument is our file path
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 means we will get some warning right ? I am expecting we wont be able to understand the string post ";" and should throw. Can you check ?
|
||
internal class ArgumemtProcessorUtilities | ||
{ | ||
public static readonly char[] SemiColonArgumentSeperator = { ';' }; |
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: Separator*
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.
done
using System; | ||
using System.Collections.Generic; | ||
|
||
internal class ArgumemtProcessorUtilities |
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: Argument*
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.
done
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
|
||
namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities |
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.
should this also handle validation of arguments based on a list? instead of just returning any value from the raw string?
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.
We are handling the validation of argument here.
Include kaadhina PR and makes changes there as well. |
/// Initializes the tracing with custom log file and trace level. | ||
/// Overrides if any trace is set before. | ||
/// </summary> | ||
/// <param name="customLogFile">Customr log file for trace messages.</param> |
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:custom
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.
done
(PlatformTraceLevel)traceLevelInt : | ||
PlatformTraceLevel.Verbose; | ||
|
||
EqtTrace.Warning("DataCollectorMain.Run: Invalid trace level: {0}, defaulting to vebose tracelevel.", traceLevelInt); |
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 will log always. Have a proper if for the previous block.
Nit:verbose*
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.
And without Initialize, will it work ?
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.
Corrected. thanks
/// </summary> | ||
/// <param name="collectDumpKey">Collect dump key.</param> | ||
/// <returns>Flag for collect dump key valid or not.</returns> | ||
private bool ValidateCollectDumpKey(string collectDumpKey) |
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.
I am confused. How is this part of this PR ?
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.
We have made the parsing logic generic with my PR as per Mayank's PR comment. Thus blame, diag and logger have been changed to use the new generic logic.
These are just refactoring and not the code changes.
var diagArgumentList = ArgumemtProcessorUtilities.GetArgumentList(argument, ArgumemtProcessorUtilities.SemiColonArgumentSeperator, CommandLineResources.EnableDiagUsage); | ||
|
||
// Get diag file path. | ||
// Note: Even though semi colon is valid file path, we are not respecting the file name having semi-colon [As we are separating arguments based on semi colon]. |
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 means we will get some warning right ? I am expecting we wont be able to understand the string post ";" and should throw. Can you check ?
} | ||
|
||
/// <summary> | ||
/// Initialize diag loggin. |
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:logging
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.
done
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.
Description
Currently
\diag:
arg always stores logs of verbose level. This PR adds customization in diag argument to allow users to pass trace level for logs.Limitations
dotnet test
command has--diag
option. TraceLevel will not be supported in this--diag
option.