Crates.io | fmt-log |
lib.rs | fmt-log |
version | 0.1.1 |
source | src |
created_at | 2024-02-28 09:51:30.200422 |
updated_at | 2024-02-28 10:02:31.792197 |
description | Macros for logging to the console, but also returning the formatted string |
homepage | |
repository | |
max_upload_size | |
id | 1156266 |
size | 4,410 |
This module contains macros for logging to the console
using the std::println!
or std::eprintln!
macros, but also returns the
formatted string.
Disclaimer: this started as a fun experiment on how to create a custom macro like the std::println!
one, and now I'm using it to print logs and get the formatted output at the same time.
fmt_printf
exampleuse fmt_log::fmt_printf;
let s1 = "Hello";
let s2 = String::from("world!");
let n1 = 123;
let output = fmt_printf!("{}, {} {}", s1, s2, n1);
assert_eq!(output, format!("{}, {} {}", s1, s2, n1));
This will log "Hello, world! 123"
to the console.
fmt_errorf
exampleuse fmt_log::fmt_errorf;
let s1 = "Hello";
let s2 = String::from("world!");
let n1 = 123;
let output = fmt_errorf!("{}, {} {}", s1, s2, n1);
assert_eq!(output, format!("{}, {} {}", s1, s2, n1));
This will log "Hello, world! 123"
to the stderr.