Skip to content

Conversation

@inureyes
Copy link
Member

Summary

  • Adds a dedicated log panel within the TUI interface to capture and display tracing events (ERROR, WARN, INFO, DEBUG) without breaking the ratatui alternate screen layout
  • Implements LogBuffer and LogEntry structs for in-memory log storage with configurable max entries (default 1000)
  • Implements TuiLogLayer that captures tracing events and stores them in the shared buffer
  • Adds log panel view component with color-coded output by log level

Key Features

  • Log Buffer: Configurable max entries via BSSH_TUI_LOG_MAX_ENTRIES environment variable
  • Color-coded levels: ERROR=red, WARN=yellow, INFO=white, DEBUG=gray
  • Keyboard shortcuts:
    • l - Toggle log panel visibility
    • j/k - Scroll logs when panel is visible
    • +/- - Resize panel (3-10 lines)
    • t - Toggle timestamps
  • Auto-refresh: Detects new log entries and triggers redraw

Files Changed

New Files

  • src/ui/tui/log_buffer.rs - LogBuffer and LogEntry structs
  • src/ui/tui/log_layer.rs - TuiLogLayer implementing tracing_subscriber::Layer
  • src/ui/tui/views/log_panel.rs - Log panel view component

Modified Files

  • src/ui/tui/app.rs - Added log panel state fields and methods
  • src/ui/tui/event.rs - Added key bindings for log panel controls
  • src/ui/tui/mod.rs - Integrated log layer and panel rendering
  • src/ui/tui/views/*.rs - Added render_in_area() for layout flexibility
  • src/utils/logging.rs - Extracted filter creation for reuse
  • tests/tui_snapshot_tests.rs - Updated assertion for new footer layout

Test Plan

  • All existing tests pass (638 tests)
  • Clippy check passes with no warnings
  • Code formatted with rustfmt
  • Manual testing: verify log panel displays correctly
  • Manual testing: verify keyboard shortcuts work
  • Manual testing: verify logs are captured without breaking TUI

Fixes #104

…ut (#104)

This commit adds a dedicated log panel within the TUI interface to capture and
display tracing events (ERROR, WARN, INFO, DEBUG) without breaking the ratatui
alternate screen layout.

New files:
- src/ui/tui/log_buffer.rs: LogBuffer and LogEntry structs for in-memory storage
- src/ui/tui/log_layer.rs: TuiLogLayer implementing tracing_subscriber::Layer
- src/ui/tui/views/log_panel.rs: Log panel view component with color-coded output

Key features:
- Log buffer with configurable max entries (default 1000, BSSH_TUI_LOG_MAX_ENTRIES)
- Color-coded log levels (ERROR=red, WARN=yellow, INFO=white, DEBUG=gray)
- Toggle log panel visibility with 'l' key
- Scroll logs with j/k keys when panel is visible
- Resize panel with +/- keys (3-10 lines)
- Toggle timestamps with 't' key
- Auto-detect new log entries and trigger redraw

Modified:
- src/ui/tui/app.rs: Added log panel state fields and methods
- src/ui/tui/event.rs: Added key bindings for log panel controls
- src/ui/tui/mod.rs: Integrated log layer and panel rendering
- src/ui/tui/views/*.rs: Added render_in_area() for layout flexibility
- src/utils/logging.rs: Extracted filter creation for reuse
- tests/tui_snapshot_tests.rs: Updated assertion for new footer layout
@inureyes inureyes added type:enhancement New feature or request status:review Under review priority:medium Medium priority issue labels Dec 16, 2025
@inureyes
Copy link
Member Author

inureyes commented Dec 16, 2025

Security & Performance Review

Analysis Summary

  • Scope: changed-files
  • Languages: Rust
  • Total changed files: 13
  • Total additions: 1147 lines
  • Total deletions: 22 lines
  • Tests: All 638 tests pass
  • Clippy: No warnings

Prioritized Issue Roadmap

CRITICAL Issues: 0

No critical security vulnerabilities identified.

HIGH Issues: 0

No high-severity issues identified.

MEDIUM Issues: 3

# Issue File Lines
1 Mutex lock held during formatting operations src/ui/tui/views/log_panel.rs 85-137
2 Lock contention between tracing layer and UI src/ui/tui/log_layer.rs 119-121
3 Env var parsing without upper bound validation src/ui/tui/log_buffer.rs 117-121

LOW Issues: 5

# Issue File
4 Unnecessary clone in log entry rendering views/log_panel.rs:117
5 Redundant rsplit calls for module name Multiple files
6 Magic numbers lack documentation views/log_panel.rs:32-38
7 Scroll HashMap eviction not LRU (acceptable) app.rs:192-207
8 Silent mutex poisoning handling Multiple files

Positive Observations

  • Thread-safe design with Arc<Mutex<LogBuffer>>
  • Bounded buffer with FIFO eviction prevents memory exhaustion
  • RAII TerminalGuard ensures proper cleanup
  • Comprehensive test coverage (324 lines of new tests)
  • Proper scroll position bounds checking throughout
  • No security vulnerabilities detected

Summary

Category Count
CRITICAL 0
HIGH 0
MEDIUM 3
LOW 5

Overall Assessment: This PR is safe to merge. All identified issues are quality/performance improvements rather than blocking concerns. The code demonstrates good Rust practices.

Recommendation: Consider addressing MEDIUM issues in a follow-up PR if high logging volume is expected in production use.


Review completed by Claude Code security review assistant

@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 16, 2025
@inureyes inureyes self-assigned this Dec 16, 2025
- Add upper bound validation for BSSH_TUI_LOG_MAX_ENTRIES (max: 10000)
- Reduce lock time in log_panel render by cloning entries quickly
- Add documentation comments for lock contention optimization
- Update README.md with log panel keybindings and configuration
- Update ARCHITECTURE.md with log panel architecture details
- Update manpage with log panel features and environment variable
- Move TUI logging logic from tui/mod.rs to utils/logging.rs
- Auto-detect TUI mode based on TTY and CI environment
- Use TuiLogLayer for TUI mode (captures logs to buffer)
- Use fmt layer for non-TUI mode (console output)
- Remove redundant init_tui_logging function from TUI module
- Use global log buffer shared between logging and TUI

Fixes issue where ERROR logs were breaking TUI display
- Always show Log Panel section in Help modal (not just when visible)
- Add inline keybinding hints to log panel title bar (j/k:scroll +/-:resize t:time)
- Update Help modal with descriptive text for log panel controls
@inureyes inureyes merged commit 66b4e36 into main Dec 16, 2025
1 of 2 checks passed
@inureyes inureyes deleted the feature/issue-104-tui-log-panel branch December 16, 2025 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority issue status:done Completed type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Fix error logs breaking TUI layout by adding in-TUI log panel

2 participants