Skip to content

feat: add feature-gated tracing/logging infrastructure#4

Merged
tmthecoder merged 3 commits intomainfrom
feat/tracing-logging
Feb 8, 2026
Merged

feat: add feature-gated tracing/logging infrastructure#4
tmthecoder merged 3 commits intomainfrom
feat/tracing-logging

Conversation

@tmthecoder
Copy link
Copy Markdown
Owner

Summary

Replace all println! calls with structured tracing macros and add a feature-gated logging infrastructure that library consumers can opt into without being burdened by unnecessary dependencies.

Changes

Infrastructure

  • smb-core/src/logging.rs — New module with feature-gated macro wrappers. When tracing is enabled, re-exports tracing::{trace, debug, info, warn, error, info_span, debug_span, trace_span}. When disabled, all macros compile to no-ops.
  • smb-core/Cargo.toml — Added tracing as optional dependency with tracing and logging features.
  • smb/Cargo.toml — Added tracing and tracing-subscriber as optional dependencies. Features are fully independent and opt-in.

Features (all opt-in, none forced by server)

Feature What it enables
server Async runtime (tokio, tokio-stream, tokio-util) — no tracing
tracing Structured tracing via tracing crate + tracing-subscriber
logging Everything in tracing + log crate compatibility bridge

Log level conventions

Level Usage
error! Unrecoverable failures, unexpected states
warn! Recoverable issues, parse failures handled gracefully
info! Lifecycle events: server start, connection accepted, session setup complete
debug! Operational detail: command dispatch, handler delegation, message send/receive
trace! Sensitive data only: keys, signatures, raw buffers, NTLM flags, full message dumps

Files modified (26 files, 331 insertions, 95 deletions)

New:

  • smb-core/src/logging.rs

println! → tracing (18 files):

  • smb/src/server/connection.rs, session.rs, mod.rs, message_handler.rs, tree_connect.rs, share/file_system.rs
  • smb/src/socket/message_stream/mod.rs, stream_async.rs
  • smb/src/protocol/message.rs, body/negotiate/context.rs, body/create/request_context.rs, body/create/response_context.rs, body/tree_connect/buffer.rs
  • smb/src/util/auth/spnego/der_utils.rs, spnego_token.rs, spnego_token_response.rs
  • smb/src/util/auth/ntlm/ntlm_authenticate_message.rs
  • smb/src/main.rs — subscriber init behind #[cfg(feature = "tracing")], defaults to RUST_LOG=info

Commented-out println! cleanup (4 files):

  • smb-core/src/lib.rs, smb-derive/src/attrs.rs, field.rs, field_mapping.rs

Verification

  • cargo check -p smb-core
  • cargo check -p smb-core --features tracing
  • cargo check -p smb-derive
  • cargo check -p smb_reader --features server ✅ (no tracing)
  • cargo check -p smb_reader --features "server,tracing"
  • cargo check --bin spin_server_up --features "server,tracing,anyhow"
  • grep -r println! */src/zero results

- Add tracing and tracing-subscriber as optional dependencies to smb-core and smb
- Create feature-gated logging macro wrappers in smb-core/src/logging.rs
  (no-ops when tracing feature is disabled)
- Replace all println! calls with appropriate tracing macros across 18 files:
  - error!: unrecoverable failures in handler chain
  - warn!: parse failures, degraded behavior
  - info!: server start, connection accepted, session setup complete
  - debug!: command dispatch, handler delegation, message send/receive
  - trace!: sensitive data (keys, signatures, raw buffers, NTLM flags)
- Clean up all commented-out println! calls in smb-core, smb-derive, smb
- Initialize tracing-subscriber in main.rs behind #[cfg(feature = "tracing")]
  with RUST_LOG env var support, defaulting to info level
- Features are fully independent and opt-in:
  - server: async runtime only, no tracing forced
  - tracing: structured tracing + subscriber
  - logging: tracing + log crate compatibility bridge
@tmthecoder tmthecoder merged commit 1012d12 into main Feb 8, 2026
4 of 5 checks passed
@tmthecoder tmthecoder deleted the feat/tracing-logging branch February 8, 2026 21:42
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.

1 participant