πͺΆ saydbg
A tiny, dependency-light macro crate for conditional debug printing β designed to give you
println!-style logging in debug builds, with optional color, timestamps, and file logging.
In release mode, all debug macros are completely compiled out (zero cost).
β¨ Features
β
Simple println!-style usage
β
Works only in debug mode (cfg(debug_assertions))
β
Optional colored output (--features color)
β
Optional timestamps (--features timestamp)
β
Optional file logging (--features file)
β
Zero-cost in release builds
β
MIT licensed β free for any project
π¦ Installation
Add to your projectβs Cargo.toml:
[]
= "0.2"
Optionally enable features:
[]
= { = "0.2", = ["color", "timestamp", "file"] }
π§ Example
use ;
π§± Default Output (Debug build)
[debug] Connected to database
[warn] Missing optional config file
[trace] Query took 5 ms
[error] User not found: admin
[log] Server started successfully
π With --features color
Colors (blue, yellow, red, gray, green) are added for easy scanning.
π With --features timestamp
[2025-10-08 12:11:47] [debug] Connected to database
[2025-10-08 12:11:47] [warn] Missing optional config file
βοΈ Macros
| Macro | Description | Color | Stream | Builds |
|---|---|---|---|---|
saydbg! |
General debug info | Blue | stdout |
Debug only |
sayerr! |
Errors | Red | stderr |
Debug only |
saywarn! |
Warnings | Yellow | stdout |
Debug only |
saytrace! |
Verbose trace info | Gray | stdout |
Debug only |
saylog! |
Always-on log (even in release) | Green | stdout |
All builds |
π Why use saydbg?
Because sometimes you donβt need a full logger β just some conditional, colorful debug messages that disappear in release builds.
saydbg sits between:
- βοΈ
println!()β simple but always prints - π§±
logortracingβ powerful but heavy for small tools
Perfect for:
- CLI utilities
- Tauri or WASM apps
- Embedded debugging
- Classroom or educational projects
- Quick prototypes or experiments
π§ Feature Flags
| Feature | Description | Default |
|---|---|---|
color |
Enables colored log labels via colored |
β |
timestamp |
Adds local timestamps using chrono |
β |
file |
Writes log output to a file (saydbg.log) in addition to stdout/stderr |
β |
Enable all for maximum clarity:
[]
= { = "0.2", = ["color", "timestamp", "file"] }
ποΈ File Logging (Optional Feature)
When compiled with the file feature, saydbg automatically mirrors all console output to a persistent log file (saydbg.log by default).
Enabling
Add the feature flag in your Cargo.toml:
[]
= { = "0.2", = ["file"] }
or on the command line:
Default Behavior
When enabled, each macro (e.g., saydbg!, saywarn!, sayerr!) appends its message to a file in the working directory:
saydbg.log
Example content:
[2025-10-09 11:32:17] [debug] Connected to database
[2025-10-09 11:32:18] [warn] User 'ryonb' not found in DB β inserting.
Manual Logging
You can also call the helper directly:
use write_to_log_file;
write_to_log_file;
Thread Safety
saydbg uses a global, thread-safe file handle (via once_cell + Mutex) to avoid race conditions across threads or async tasks.
This means you can freely log from multiple tasks without worrying about file corruption or interleaving.
π§© Example Project Integration
use ;
All of these compile away completely in release:
# (no debug output at all)
π License
Licensed under the MIT License.
π‘ Author
Ryon Boswell β @crookedlungs
A developer and educator creating lightweight, modular tools for Rust and education.
π Contributing
Pull requests, feature ideas, and improvements are welcome.
You can clone this repo, modify the macros, or submit suggestions on GitHub.
π¦ "Debug smart, release clean." β
saydbg