fake-log

Crates.iofake-log
lib.rsfake-log
version0.1.0
created_at2025-06-05 06:08:44.624297+00
updated_at2025-06-05 06:08:44.624297+00
descriptionA fake logging implementation with the same interface as log crate but with no-op implementation for embedded scenarios
homepagehttps://github.com/fslongjin/fake-log
repositoryhttps://github.com/fslongjin/fake-log
max_upload_size
id1701117
size32,342
LoGin (fslongjin)

documentation

https://docs.rs/fake-log

README

fake-log

A fake logging library that provides the same interface as Rust's log crate but with no-op implementations. Designed specifically for embedded scenarios where reducing memory footprint is critical.

Features

  • 🚀 Zero Overhead: All logging macros are optimized away at compile time
  • 📦 Full Compatibility: Provides exactly the same API as the log crate
  • 🔧 No Dependencies: Supports no_std environments with minimal dependencies
  • âš¡ Compile-time Optimization: Supports compile-time log level filtering
  • 🎯 Embedded Friendly: Designed specifically for embedded and resource-constrained environments

Use Cases

  • Embedded systems where memory usage needs to be minimized
  • Production environments where logging should be completely disabled
  • Testing environments where log output would be distracting
  • Library development with optional logging support

Installation

Add to your Cargo.toml:

[dependencies]
fake-log = "0.1"

Basic Usage

Drop-in Replacement for log crate

If your project already uses the log crate, you can quickly replace it:

[dependencies]
# log = "0.4"  # Comment out the original log dependency
fake-log = { version = "0.1", package = "log" }  # Use fake-log as replacement

Your existing code requires no changes.

Direct Usage

extern crate fake_log as log;

fn main() {
    // These calls produce no output and allocate no memory
    log::info!("Application started");
    log::debug!("Debug info: {}", 42);
    log::error!("Error message");
    log::warn!("Warning message");
    log::trace!("Trace message");
    
    // Support for target parameter
    log::info!(target: "my_module", "Module-specific log");
}

Comparison with log crate

Feature log crate fake-log
Runtime overhead Small overhead Zero overhead
Memory allocation May allocate Zero allocation
Binary size Slightly larger Minimal
Configuration complexity Requires Logger setup No configuration needed
Embedded support Good Excellent

Examples

See complete examples in the examples/ directory:

cargo run --example basic
cargo run --example no_std
cargo run --example custom_logger

no_std Support

fake-log fully supports no_std environments:

#![no_std]

use fake_log::{info, error};

fn embedded_function() {
    info!("Running in no_std environment");
    error!("Error handling");
}

fake-log should perform best in all scenarios since it does nothing.

License

This project is licensed under MIT OR Apache-2.0, consistent with the Rust ecosystem.

Contributing

Issues and pull requests are welcome!

FAQ

Q: Why do I need fake-log? A: In embedded systems, even the lightest logging libraries can consume precious stack memory resources. fake-log provides a completely zero-overhead solution.

Q: Can I switch to real logging at runtime? A: No. fake-log is designed for compile-time optimization, and all log calls are removed at compile time.

Q: How can I use real logging during development and fake-log in production? A: You can use Cargo features and conditional compilation to achieve this switching.

Related Projects

  • log - Rust's standard logging facade
  • env_logger - Environment variable configured logger
  • slog - Structured logging library
Commit count: 2

cargo fmt