Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Shared.CLI/BaseTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ protected void SelectOutput(string outputFile)
}
}

protected void ConfigureLogging(BaseToolOptions options)
{
if (options.EnableTraceLogging)
{
var config = NLog.LogManager.Configuration;
var rule = config.LoggingRules.FirstOrDefault();
if (rule != null)
{
rule.SetLoggingLevels(NLog.LogLevel.Trace, NLog.LogLevel.Fatal);
NLog.LogManager.ReconfigExistingLoggers();
}
}
}

private bool redirectConsole = false;
}
}
3 changes: 3 additions & 0 deletions src/Shared.CLI/Options/BaseToolOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ namespace Microsoft.CST.OpenSource.OssGadget.Options;

public class BaseToolOptions
{
[Option('t', "trace", Required = false, Default = false,
HelpText = "Enable trace-level logging")]
public bool EnableTraceLogging { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

You've added an option to enable trace logging to the BaseToolOptions which is used by most, if not all, commands in OSSGadget. However, your change only enables trace logging for the DownloadTool. This will be confusing for users.

Suggestions

  1. Allow the user to specify the log level using either string or numeric values. See nlog log levels and CommandLineParser docs

  2. The log level configuration should be respected across all commands. Ideally this logic isn't distributed across the commands (perhaps in BaseTool?)

}
2 changes: 2 additions & 0 deletions src/Shared.CLI/Tools/DownloadTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public DownloadTool(ProjectManagerFactory projectManagerFactory)

public override async Task<ErrorCode> RunAsync(DownloadToolOptions options)
{
ConfigureLogging(options);

if (options.Targets is IEnumerable<string> targetList && targetList.Any())
{
foreach (string? target in targetList)
Expand Down