A beautiful, tiny traceback and logging library supporting #![no_std] rust.

Overview

breadcrumbs

Breadcrumbs is a beautiful, tiny traceback and logging library for Rust that offers seamless integration with #![no_std], multi-threading and concurrency.

Features

  • Beautifully-formatted traceback of logs (supporting Display and Debug)
  • Dynamic log levels
  • Dynamic log channels
  • Seamless integration with #![no_std]
  • Multi-threading and concurrent logging supported with no special syntax
  • Easy-to-use macros
  • Support for listeners to be notified of new logs

Usage

Add the following to your Cargo.toml:

[dependencies]
breadcrumbs = "0.1.5"

Then, initalize breadcrumbs once in your main.rs or lib.rs:

use breadcrumbs::init;

init!();

You can set a custom log listener with ease by implementing the LogListener trait:

use breadcrumbs::{init, LogListener, Log, LogLevel};

struct MyLogListener;
 
impl LogListener for MyLogListener {
    fn on_log(&mut self, log: Log) {
        if log.level.is_at_least(LogLevel::Warn) {
            println!("{}", log);
        } else {
            // πŸ’‘ New in 0.1.5 - Remove unnecessary logs to save memory
            // Useful in embedded usecases
            log.remove();
        }
    }
}
 
init!(MyLogListener);

Then, simply use the log! macro from or its variants from anywhere to log messages:

use breadcrumbs::{log, log_level, log_channel, LogLevel};

// A basic log message
log!("Hello, world!");

// A log message with a custom level
log_level!(LogLevel::Info, "Test log message");

// A log message with a custom channel
log_channel!("test_channel", "Test log message");

// A log message with a custom channel and level
log!(LogLevel::Info, "test_channel", "Test log message");

Access a traceback of log messages from anywhere with the traceback! macro or its variants:

use breadcrumbs::{traceback, traceback_channel, traceback_level, LogLevel};

// A basic traceback, fetching all logged messages
let t = traceback!();

// A traceback with a custom channel, fetching messages in this channel
let t = traceback_channel!("my-channel");

// A traceback with a custom level, fetching messages of this level or higher
let traceback = traceback_level!(LogLevel::Warn);

// A traceback with a custom channel and level, fetching messages in this channel of this level or higher
let traceback = traceback!(LogLevel::Warn, "test_channel");

Traceback and Log objects beautifully implement Display and Debug:

use breadcrumbs::traceback;

let t = traceback!();
println!("{}", t);
println!("{:?}", t);

Example

use breadcrumbs::{init, log, log_level, log_channel, traceback, LogLevel, LogListener, Log};

struct MyLogListner;

impl LogListener for MyLogListner {
    fn on_log(&mut self, log: Log) {
        if log.level.is_at_least(LogLevel::Warn) {
            println!("{}", log);
        }
    }
}

fn main() {
    init!(MyLogListner);

    log!("Hello, world!");
    log_level!(LogLevel::Info, "Test log message");
    log_channel!("test_channel", "Test log message");
    log!(LogLevel::Warn, "test_channel", "Test log message");

    let t = traceback!();
    println!("Fatal Error! Traceback:\n{}", t);
}
You might also like...
Yet Another Kalman Filter Implementation. As well as Lie Theory (Lie group and algebra) on SE(3). [no_std] is supported by default.

yakf - Yet Another Kalman Filter Yet Another Kalman Filter Implementation, as well as, Lie Theory (Lie group, algebra, vector) on SO(3), SE(3), SO(2),

An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust.

Pinenut Log δΈ­ζ–‡ζ–‡ζ‘£ ・ English An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust. Overview Compression Pin

Logging for text that should stay in the same place in a console.

console_static_text Crate for logging text that should stay in the same place in a console. This measures words to handle wrapping and has some consol

Supporting code for the paper "Optimized Homomorphic Evaluation of Boolean Functions" submitted to Eurocrypt 2024

This repository contains the code related to the paper Optimized Homomorphic Evaluation of Boolean Functions. The folder search_algorithm contains the

A tiny library and application for animating text in the terminal.
A tiny library and application for animating text in the terminal.

🐌 snailshell A tiny library and application for animating text in the terminal. πŸͺ„ It's so easy to add some flair to your text RPGs or console progra

Tiny Rust library to draw pretty line graphs using ascii characters.

rasciigraph Tiny Rust library to draw pretty line graphs using ascii characters. Usage Add this to your Cargo.toml [dependencies] rasciigraph = "0.1.1

Tiny color conversion library for TUI application builders
Tiny color conversion library for TUI application builders

Definition of ANSI, RGB and HSL color types and all the conversions between them. There are many other color conversion crates. This one may be useful

A tiny crate to make it easy to share and apply Git hooks for Rust projects
A tiny crate to make it easy to share and apply Git hooks for Rust projects

Shareable git hooks for Rust project. Sloughi is a friend of Husky from North Africa! :algeria:

For something between the likes of a toy bootloader or tiny kernel and Arch Linux.

For something between the likes of a toy bootloader or tiny kernel and Arch Linux.

Owner
Michael
Have a great day! πŸ˜ƒ
Michael
A super simple but lightweight logging library that tries to capture the most important (status) information.

Hackerlog A super simple but lightweight logging library that tries to capture the most important (status) information. The following is supported: Lo

434b 3 Aug 22, 2023
A beautiful and feature-packed Apple Music CLI

am A beautiful and feature-packed Apple Music CLI! Written in Rust. Installation Nix (recommended) This GitHub repository contains a flake. Add github

Ryan Cao 5 Sep 21, 2023
A Rust command that prettifies the ugly `cargo test` output into a beautiful one.

Cargo Pretty Test ✨ A Rust command-line tool that prettifies the ugly cargo test output into a beautiful output. This crate can be also used as a libr

Jose Celano 105 Oct 10, 2023
:large_orange_diamond: Build beautiful terminal tables with automatic content wrapping

Comfy-table Comfy-table tries to provide utility for building beautiful tables, while being easy to use. Features: Dynamic arrangement of content to a

Arne Beer 525 Jan 8, 2023
More beautiful HTML reports for llvm-cov/cargo-llvm-cov

?? llvm-cov-pretty More beautiful HTML reports for llvm-cov (cargo-llvm-cov specifically). Dark theme support (switches automatically based on your br

Dominik Nakamura 13 Jun 26, 2023
Beautiful, minimal, opinionated CLI prompts inspired by the Clack NPM package

Effortlessly build beautiful command-line apps with Rust ?? ✨ Beautiful, minimal, opinionated CLI prompts inspired by the @clack/prompts npm package.

Alexander Fadeev 7 Jul 23, 2023
Make beautiful colored code listings in LaTeX with the power of TreeSitter.

What is this? This is a CLI tool that consumes TreeSitter's output and transforms it into LaTeX code that will produce syntax-colored code listing. If

TomΓ‘Ε‘ Lebeda 11 Sep 4, 2023
Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions

Abscissa is a microframework for building Rust applications (either CLI tools or network/web services), aiming to provide a large number of features w

iqlusion 524 Dec 26, 2022
garbage-collecting on-disk object store, supporting higher level KV stores and databases.

marble Garbage-collecting disk-based object-store. See examples/kv.rs for a minimal key-value store built on top of this. Supports 4 methods: read: de

Komora 215 Dec 30, 2022
✨ sleek typing tui with visualized results and historical logging

thokr ✨ sleek typing tui with visualized results and historical logging Usage For detailed usage run thokr -h. thokr 0.4.1 sleek typing tui with visua

colby thomas 440 Dec 30, 2022