Feature/kamalesh logrus logging #289
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request: Add Verbose Logging Flag to litmusctl
Description
This PR implements a global
--verbose(or-v) flag to enable detailed logging during command execution. By default, litmusctl maintains minimal logging, but with verbose mode enabled, users can see detailed information about API calls, request/response payloads, and internal operations - making debugging and troubleshooting much easier.Related Issue(s)
Fixes #284
Type of Change
Changes Made
1. Created Logging Utility (
pkg/utils/logger.go)logruslibraryInitLogger()function to configure log level based on verbose modeLogVerbose()helper function for conditional debug logging2. Added Verbose Mode Configuration (
pkg/config/ops.go)VerboseModeglobal variable to track verbose flag state3. Integrated Verbose Flag in Root Command (
pkg/cmd/root/root.go)--verbosepersistent flag (short form:-v) to root commandinitConfig()functionconfig.VerboseModebased on flag value4. Enhanced API Request Logging (
pkg/apis/request.go)5. Added Command-Level Logging
pkg/cmd/connect/infra.go: Logs infrastructure connection details, platform info, project IDpkg/cmd/get/get.go: Logs query operations and project contextpkg/cmd/create/project.go: Logs project creation details and API responses6. Updated Documentation (
README.md)-vand--verboseflagsHow Has This Been Tested?
Test Configuration:
Testing Steps
1. Build the Binary
cd /Users/kd14/Desktop/litmusctl go build -o litmusctl main.go2. Test Verbose Flag Appears in Help
Expected: The
--verboseflag should appear in the global flags section3. Test Verbose Mode Enabled
Expected: Should see
DEBU[0000] Verbose mode enabledmessage4. Test Normal Mode (Default)
Expected: Should NOT see debug messages, only regular output
5. Test Short Flag
Expected: Verbose logging should work with
-vas well6. Test with Actual API Commands (if Chaos Center is available)
Expected: Should see detailed API request/response logs
Screenshots/Demo
Without Verbose Flag (Default Behavior)
With Verbose Flag Enabled
Verbose Flag in Help Output
Checklist
Additional Notes
Design Decisions
Used Logrus Library: Already a dependency in the project, well-maintained, and provides structured logging with levels.
Global Flag: Made
--verbosea persistent flag on the root command so it's available to all subcommands without repetition.Minimal Changes: Strategically added logging to key areas (API requests, common commands) without overwhelming the codebase. More logging can be added incrementally as needed.
Backward Compatible: Default behavior remains unchanged - users won't see any difference unless they explicitly use the
--verboseflag.Clear Documentation: Added comprehensive README section so users understand when and how to use verbose mode.
What Gets Logged in Verbose Mode
Future Enhancements
While this PR provides comprehensive verbose logging for the most common operations, additional verbose logging can be added to other commands as needed:
The foundation is now in place - developers can easily add more verbose logging by calling
utils.LogVerbose()wherever additional debugging information would be helpful.Benefits
Summary
This PR successfully implements issue #284 by adding a global
--verboseflag that enables detailed logging throughout litmusctl. The implementation is clean, well-documented, backward-compatible, and ready for review.