Skip to content

Refactor logging/debugging approach across codebase #363

Closed

Description

@malibio

Summary

The codebase has inconsistent logging practices across both frontend and backend. While logging infrastructure exists (TypeScript Logger utility and Rust tracing), it's largely unused. This issue tracks the comprehensive migration to consistent, structured logging.

Current State Analysis

Frontend (TypeScript/Svelte)

  • 328 total console statements across the codebase
    • 126 console.log (informational - many should be debug or use Logger)
    • 96 console.error (appropriate for errors)
    • 72 console.warn (appropriate for warnings)
    • 31 console.debug (appropriate)
    • 3 console.info (should use Logger)
  • Logger utility exists at `src/lib/utils/logger.ts` but 0 files import it
  • ~42 console.log in test files (acceptable for test output)

Heavy Offenders (console.log count):

  • `browser-sync-service.ts`: 16
  • `developer-inspector.ts`: 9
  • `base-node-viewer.svelte`: 7
  • `app-shell.svelte`: 7
  • `schema-plugin-loader.ts`: 6
  • `app-initialization.ts`: 5
  • Various node type files: 2-4 each

Backend (Rust)

  • 130 total logging statements
    • 28 `println!` (startup messages in dev binaries - acceptable)
    • 24 `eprintln!` (error messages - should use tracing::error!)
    • 28 `tracing::info!` (proper usage)
    • 12 `tracing::debug!` (proper usage)
    • 10 `tracing::error!` (proper usage)
    • Mixed `warn!/error!/debug!/info!` macros (11 total)
  • tracing crate configured in Cargo.toml but inconsistently used
  • Dev binaries (`dev-mcp.rs`, `dev-proxy.rs`) use `println!` for startup - appropriate for CLI output

Proposed Solution

Phase 1: Frontend Logger Migration

1.1 Enhance existing Logger utility:
```typescript
// Current: basic logger with prefix support
// Enhance with:

  • Environment-aware default levels (dev: debug, prod: warn)
  • Structured data support with proper formatting
  • Group/timing utilities for debugging
  • Color-coded output in development
    ```

1.2 Migration strategy for console statements:

Current New Criteria
`console.log` (info) `logger.info()` Operational info user/dev should see
`console.log` (debug) `logger.debug()` Debug info only for troubleshooting
`console.error` `logger.error()` Actual errors
`console.warn` `logger.warn()` Warnings that don't block operation
`console.debug` `logger.debug()` Already debug level

1.3 Files to migrate (priority order):

  1. Services (~40 console.log) - core business logic
  2. Components (~15 console.log) - UI components
  3. Plugins (~9 console.log) - plugin system
  4. Types (~16 console.log) - node type definitions
  5. Utils (~3 console.log) - utility functions

Phase 2: Backend Tracing Standardization

2.1 Standardize on tracing macros:

  • Replace remaining `println!` in library code with `tracing::info!`
  • Replace `eprintln!` with `tracing::error!`
  • Keep `println!` in `main()` functions for CLI startup banners (user-facing)
  • Use consistent macro style: `tracing::level!` not bare `level!`

2.2 Files to update:

  • `src/lib.rs` - any println! in library code
  • `src/commands/db.rs` - database command logging
  • Review other modules for consistency

Phase 3: ESLint Rules (Optional)

Add ESLint rules to prevent regression:
```javascript
'no-console': ['warn', { allow: ['warn', 'error', 'debug'] }]
```

Acceptance Criteria

Must Have

  • All frontend services use Logger instead of raw console.*
  • All frontend components use Logger instead of raw console.*
  • All frontend plugins use Logger instead of raw console.*
  • Logger utility enhanced with environment-aware defaults
  • Production console clean - only errors/warnings visible by default
  • Debug logs work via browser devtools level filtering
  • Backend library code uses tracing consistently (no println! in lib)
  • Test files excluded from migration (console.log acceptable in tests)

Nice to Have

  • ESLint rule to warn on new console.log usage
  • Logging documentation added to development guide
  • Performance impact verified (Logger overhead minimal)

Implementation Notes

Frontend Logger already exists at:
`packages/desktop-app/src/lib/utils/logger.ts`

Features already implemented:

  • Test-aware (auto-disables in VITEST)
  • Log level filtering
  • Prefix support for service identification
  • Structured data parameter support

Rust tracing already configured in:
`packages/desktop-app/src-tauri/Cargo.toml`

  • tracing = "0.1"
  • tracing-subscriber with env-filter

References

Activity

  1. malibio commented on Dec 4, 2025

    @malibio
    CollaboratorAuthor

    Test baseline: Frontend 728 passed, Rust 584 passed (3 ignored)

  2. self-assigned this
    on Dec 4, 2025
  3. malibio commented on Dec 4, 2025

    @malibio
    CollaboratorAuthor

    Phase 1 complete - WIP commit pushed (16559da)

    Completed:

    • Enhanced Logger utility with environment-aware defaults
    • Migrated key services: browser-sync-service, app-initialization, navigation-service
    • Migrated schema-plugin-loader
    • All tests passing (1569)

    Remaining:

    • ~204 console statements left in lib (down from 328+)
    • Need to migrate remaining services, components, node types
    • Rust backend tracing standardization

    See commit message for full details: 16559da

  4. added 2 commits that reference this issue on Dec 4, 2025
    8c3aba7
    b1fd36c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions