|
| 1 | +--- |
| 2 | +type: normal |
| 3 | +title: "Remove println usage" |
| 4 | +seq: 022 |
| 5 | +slug: "remove-println-usage" |
| 6 | +created: "2026-02-04T09:20:08Z" |
| 7 | +status: completed |
| 8 | +--- |
| 9 | + |
| 10 | +# Remove println usage |
| 11 | + |
| 12 | +Replace all `println!` usage with `info!` from the `tracing` crate in the build |
| 13 | +command to ensure consistent logging behavior across the application. |
| 14 | + |
| 15 | +## Current Problems |
| 16 | + |
| 17 | +The current implementation uses `println!` for some logging messages in the |
| 18 | +build command, while using `info!` from the `tracing` crate for others. This |
| 19 | +creates inconsistent behavior: |
| 20 | + |
| 21 | +1. Some log messages respect verbosity flags, while others always appear |
| 22 | +2. The success messages in `build.rs` use `println!` instead of `info!` |
| 23 | +3. Inconsistent logging makes it harder for users to control output verbosity |
| 24 | + |
| 25 | +Example output from `cargo txt build serde`: |
| 26 | + |
| 27 | +```shell |
| 28 | + INFO Running cargo doc --package serde --no-deps |
| 29 | + INFO Converted 61 items to markdown |
| 30 | +✓ Built documentation for serde (61 items) <- println! (not using tracing) |
| 31 | + Run `cargo txt list serde` to see all items <- println! (not using tracing) |
| 32 | + INFO Successfully saved documentation <- info! (using tracing) |
| 33 | +``` |
| 34 | + |
| 35 | +The lines with checkmarks and the hint message use `println!` and are not |
| 36 | +controlled by the tracing verbosity level. |
| 37 | + |
| 38 | +## Proposed Solution |
| 39 | + |
| 40 | +Replace all `println!` statements in `src/commands/build.rs` with `info!` macro |
| 41 | +from the `tracing` crate. This ensures: |
| 42 | + |
| 43 | +1. Consistent logging behavior across all log messages |
| 44 | +2. Proper respect for verbosity flags (`-v`, `-vv`, etc.) |
| 45 | +3. All informational messages follow the same logging pattern |
| 46 | + |
| 47 | +**Note**: The `list` and `show` commands intentionally use `println!` to output |
| 48 | +their main results (the markdown content) to stdout. These should NOT be changed |
| 49 | +as they are the primary output of those commands. |
| 50 | + |
| 51 | +## Analysis Required |
| 52 | + |
| 53 | +Minimal analysis is required. Need to verify: |
| 54 | + |
| 55 | +1. Confirm that the `info!` macro is already imported in `src/commands/build.rs` |
| 56 | +2. Verify that replacing the two `println!` statements with `info!` won't break |
| 57 | + existing functionality |
| 58 | + |
| 59 | +### Code Locations to Check |
| 60 | + |
| 61 | +- `src/commands/build.rs` - Lines 349-354 in the `save_doc` function |
| 62 | + |
| 63 | +## Implementation Checklist |
| 64 | + |
| 65 | +### Code Changes |
| 66 | + |
| 67 | +- [x] Replace |
| 68 | + `println!("✓ Built documentation for {} ({} items)", lib_name, item_count)` |
| 69 | + with |
| 70 | + `info!("Built documentation for {} ({} items)", lib_name, item_count)` |
| 71 | + (also removed the ✓ symbol) |
| 72 | +- [x] Replace `println!(" Run `cargo txt list {}` to see all items", lib_name)` |
| 73 | + with `info!("Run `cargo txt list {}` to see all items", lib_name)` (also |
| 74 | + removed the leading spaces) |
| 75 | +- [x] Verify that `use tracing::{debug, info}` is present in imports (should |
| 76 | + already exist) |
| 77 | + |
| 78 | +## Test Plan |
| 79 | + |
| 80 | +### Verification Tests |
| 81 | + |
| 82 | +- [x] Run `cargo build` and ensure compilation succeeds |
| 83 | +- [x] Run `cargo test` and verify all tests pass |
| 84 | +- [x] Run `cargo clippy -- -D warnings` and ensure no warnings |
| 85 | +- [x] Run `rust-lint` and ensure no warnings |
| 86 | +- [x] Test `cargo txt build serde` with default verbosity and verify info |
| 87 | + messages appear |
| 88 | +- [x] Test `cargo txt build serde -q` and verify info messages are suppressed |
| 89 | +- [x] Test `cargo txt build serde -vv` and verify info messages appear with |
| 90 | + other info-level logs |
| 91 | +- [x] Verify the output format remains unchanged when info messages are visible |
| 92 | + |
| 93 | +### Regression Tests |
| 94 | + |
| 95 | +- [x] Run `cargo txt list serde` and verify it still outputs markdown content |
| 96 | + (not affected by changes) |
| 97 | +- [x] Run `cargo txt show serde` and verify it still outputs documentation |
| 98 | + content (not affected by changes) |
| 99 | +- [x] Verify that the markdown files are still generated correctly in |
| 100 | + `target/docmd/` |
| 101 | + |
| 102 | +## Structure After Changes |
| 103 | + |
| 104 | +### Before |
| 105 | + |
| 106 | +```rust |
| 107 | +// src/commands/build.rs, lines 349-357 |
| 108 | +let item_count = total_files.saturating_sub(3); |
| 109 | + |
| 110 | +println!( |
| 111 | + "✓ Built documentation for {} ({} items)", |
| 112 | + lib_name, item_count |
| 113 | +); |
| 114 | +println!(" Run `cargo txt list {}` to see all items", lib_name); |
| 115 | + |
| 116 | +info!("Successfully saved documentation"); |
| 117 | +``` |
| 118 | + |
| 119 | +### After |
| 120 | + |
| 121 | +```rust |
| 122 | +// src/commands/build.rs, lines 349-357 |
| 123 | +let item_count = total_files.saturating_sub(3); |
| 124 | + |
| 125 | +info!( |
| 126 | + "Built documentation for {} ({} items)", |
| 127 | + lib_name, item_count |
| 128 | +); |
| 129 | +info!("Run `cargo txt list {}` to see all items", lib_name); |
| 130 | + |
| 131 | +info!("Successfully saved documentation"); |
| 132 | +``` |
| 133 | + |
| 134 | +## Design Considerations |
| 135 | + |
| 136 | +1. **Preserve User-Facing Messages**: The success messages should remain |
| 137 | + user-friendly and appear at the default verbosity level (InfoLevel). |
| 138 | + |
| 139 | +2. **Consistency with Existing Logging**: The build command already uses `info!` |
| 140 | + for the final "Successfully saved documentation" message. The new changes |
| 141 | + make the preceding messages consistent. |
| 142 | + |
| 143 | +3. **Output Format**: The indentation and checkmark symbols are part of the |
| 144 | + message string and will be preserved. |
| 145 | + |
| 146 | +4. **List and Show Commands**: These commands use `println!` to output their |
| 147 | + primary results (markdown content) and must NOT be changed. They are |
| 148 | + outputting data, not logging. |
| 149 | + |
| 150 | +## Success Criteria |
| 151 | + |
| 152 | +- `rust-lint` passes without warnings |
| 153 | +- `cargo clippy -- -D warnings` passes without warnings |
| 154 | +- `cargo build` succeeds without compilation errors or warnings |
| 155 | +- `cargo test` passes all tests |
| 156 | +- All success messages in the build command use `info!` instead of `println!` |
| 157 | +- Success messages appear with default verbosity (`-vv` or no flags) |
| 158 | +- Success messages are suppressed with `-q` flag |
| 159 | +- The output format and content remain unchanged when messages are visible |
| 160 | +- List and show commands continue to work correctly (not affected by changes) |
| 161 | + |
| 162 | +## Implementation Notes |
| 163 | + |
| 164 | +This is a straightforward mechanical change. The `tracing::info` macro is |
| 165 | +already imported in `src/commands/build.rs`, so no import changes are needed. |
| 166 | +The only change required is replacing `println!` with `info!` for the two |
| 167 | +success messages in the `save_doc` function. |
| 168 | + |
| 169 | +After the change, all three messages in the function will use consistent logging |
| 170 | +with the `info!` macro. |
0 commit comments