Skip to content

Conversation

@Kamalesh-Seervi
Copy link

@Kamalesh-Seervi Kamalesh-Seervi commented Oct 29, 2025

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

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Changes Made

1. Created Logging Utility (pkg/utils/logger.go)

  • Implemented centralized logging using the logrus library
  • Added InitLogger() function to configure log level based on verbose mode
  • Default: INFO level (minimal logs)
  • Verbose mode: DEBUG level (detailed logs)
  • Added LogVerbose() helper function for conditional debug logging

2. Added Verbose Mode Configuration (pkg/config/ops.go)

  • Added VerboseMode global variable to track verbose flag state
  • Accessible throughout the codebase for conditional logging

3. Integrated Verbose Flag in Root Command (pkg/cmd/root/root.go)

  • Added --verbose persistent flag (short form: -v) to root command
  • Made flag available globally to all subcommands
  • Integrated logger initialization in initConfig() function
  • Sets config.VerboseMode based on flag value

4. Enhanced API Request Logging (pkg/apis/request.go)

  • Added verbose logging for all HTTP requests:
    • HTTP method and full URL
    • Request payload (GraphQL queries/mutations)
    • Response data (when successful)
  • Helps users understand exactly what API calls are being made

5. Added Command-Level Logging

  • pkg/cmd/connect/infra.go: Logs infrastructure connection details, platform info, project ID
  • pkg/cmd/get/get.go: Logs query operations and project context
  • pkg/cmd/create/project.go: Logs project creation details and API responses

6. Updated Documentation (README.md)

  • Added new "Verbose Mode" section explaining the feature
  • Included usage examples with both -v and --verbose flags
  • Documented what information gets logged in verbose mode
  • Listed default behavior vs. verbose behavior
  • Provided practical examples for common commands

How Has This Been Tested?

  • Manual testing
  • Unit tests (logging doesn't require new unit tests, but existing tests still pass)

Test Configuration:

  • litmusctl version: 1.24.2 (dev)
  • OS: macOS
  • Go version: 1.21+ (inferred from go.mod)

Testing Steps

1. Build the Binary

cd /Users/kd14/Desktop/litmusctl
go build -o litmusctl main.go

2. Test Verbose Flag Appears in Help

./litmusctl --help

Expected: The --verbose flag should appear in the global flags section

3. Test Verbose Mode Enabled

./litmusctl version --verbose
./litmusctl config view --verbose

Expected: Should see DEBU[0000] Verbose mode enabled message

4. Test Normal Mode (Default)

./litmusctl version
./litmusctl config view

Expected: Should NOT see debug messages, only regular output

5. Test Short Flag

./litmusctl get projects -v

Expected: Verbose logging should work with -v as well

6. Test with Actual API Commands (if Chaos Center is available)

litmusctl get projects --verbose
litmusctl create project --name test-project --verbose
litmusctl connect chaos-infra --name test-infra --verbose

Expected: Should see detailed API request/response logs

Screenshots/Demo

Without Verbose Flag (Default Behavior)

$ ./litmusctl config view
File reading error open /Users/kd14/.litmusconfig : no such file or directory. Use --config or -c flag to point the configfile

With Verbose Flag Enabled

$ ./litmusctl config view --verbose
DEBU[0000] Verbose mode enabled                         
File reading error open /Users/kd14/.litmusconfig : no such file or directory. Use --config or -c flag to point the configfile

Verbose Flag in Help Output

$ ./litmusctl --help
Flags:
      --cacert string   cacert <path_to_crt_file> , custom ca certificate used for communicating with portal
      --config string   config file (default is $HOME/.litmusctl)
  -h, --help            help for litmusctl
      --skipSSL         skipSSL, litmusctl will skip ssl/tls verification while communicating with portal
  -v, --verbose         enable verbose logging (shows request payloads, API endpoints, and additional details)

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works (N/A - logging feature)
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published (N/A)
  • I have updated the README.md if needed
  • I have checked compatibility with the latest version of Chaos Center

Additional Notes

Design Decisions

  1. Used Logrus Library: Already a dependency in the project, well-maintained, and provides structured logging with levels.

  2. Global Flag: Made --verbose a persistent flag on the root command so it's available to all subcommands without repetition.

  3. Minimal Changes: Strategically added logging to key areas (API requests, common commands) without overwhelming the codebase. More logging can be added incrementally as needed.

  4. Backward Compatible: Default behavior remains unchanged - users won't see any difference unless they explicitly use the --verbose flag.

  5. Clear Documentation: Added comprehensive README section so users understand when and how to use verbose mode.

What Gets Logged in Verbose Mode

  • ✅ Command execution start
  • ✅ API endpoint URLs
  • ✅ HTTP methods (GET, POST, etc.)
  • ✅ GraphQL query/mutation payloads
  • ✅ Response data from API calls
  • ✅ Project IDs, infrastructure IDs, and other resource identifiers
  • ✅ Platform detection (k8s cluster info)
  • ✅ Configuration file operations

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:

  • Describe commands
  • Delete operations
  • Update operations
  • Upgrade operations

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

  1. Easier Debugging: Users can now see exactly what litmusctl is doing internally
  2. Better Support: When users report issues, they can provide verbose logs for troubleshooting
  3. Transparency: Users can understand what API calls are being made and what data is being sent
  4. Development: Developers working on litmusctl can use verbose mode to debug new features
  5. Non-Intrusive: Default behavior unchanged, opt-in feature

Summary

This PR successfully implements issue #284 by adding a global --verbose flag that enables detailed logging throughout litmusctl. The implementation is clean, well-documented, backward-compatible, and ready for review.

Added debug logging for API requests and responses.

Signed-off-by: Kamalesh Seervi <[email protected]>
Added informational log for connecting infrastructure with credentials.

Signed-off-by: Kamalesh Seervi <[email protected]>
Added debug statements to track project creation flow.

Signed-off-by: Kamalesh Seervi <[email protected]>
Added debug logging for project fetching process.

Signed-off-by: Kamalesh Seervi <[email protected]>
Added a verbose mode flag to enable detailed logging.

Signed-off-by: Kamalesh Seervi <[email protected]>
Implement a logger utility with various log levels.

Signed-off-by: Kamalesh Seervi <[email protected]>
Added documentation for verbose mode in litmusctl.

Signed-off-by: Kamalesh Seervi <[email protected]>
Signed-off-by: Kamalesh D [email protected]
Signed-off-by: Kamalesh Seervi <[email protected]>
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 --verbose flag for detailed logging

1 participant