Skip to content

Conversation

@vamsipolavarapu-msft
Copy link

Enabled command line trace logging option to print the package URL during download.

Changes:

  • \OSSGadget\src\Shared.CLI\Options\BaseToolOptions.cs
  • \OSSGadget\src\Shared.CLI\BaseTool.cs
  • \OSSGadget\src\Shared.CLI\Tools\DownloadTool.cs

Output
image

{
[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?)

@danfiedler-msft
Copy link
Contributor

Based on the output in the PR description, the full URL for the downloaded file isn't in the trace output either. It looks like we need another log statement. I'd expect to see output with something like: Downloading package from: https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz

Refactored logging in `BaseTool.cs` to support various log levels with a new `ParseLogLevel` method, allowing both string and numeric inputs. Updated `BaseToolOptions.cs` to replace `EnableTraceLogging` with a more flexible `LogLevel` option.

Introduced `LogDownload` method in `BaseProjectManager.cs` to streamline logging of download operations, replacing repetitive code across multiple project manager classes. This enhances code consistency, maintainability, and readability.
@vamsipolavarapu-msft
Copy link
Author

Updated log messages

image

Copilot generated:

This pull request introduces an option to enable trace-level logging for CLI tools, improving debugging and visibility into tool execution. The main change is the addition of a new command-line option and the associated logic to configure logging based on user input.

Logging enhancements:

  • Added a new EnableTraceLogging boolean property to BaseToolOptions, allowing users to enable trace-level logging via the --trace command-line option.
  • Implemented the ConfigureLogging method in BaseTool to set logging levels to Trace when the option is enabled, and integrated it into the tool execution flow (called in DownloadTool.RunAsync). [1] [2]

@vamsipolavarapu-msft
Copy link
Author

/azp run

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 516 in repo microsoft/OSSGadget

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.

3 participants