Crates.io | better-logger |
lib.rs | better-logger |
version | 1.0.3 |
created_at | 2025-04-20 23:34:49.336394+00 |
updated_at | 2025-05-20 21:16:32.807073+00 |
description | Flexible sync/async logger with console, file, and HTTP output |
homepage | https://github.com/Gistyr/better-logger |
repository | https://github.com/Gistyr/better-logger |
max_upload_size | |
id | 1642104 |
size | 1,702,495 |
✔️ Native Environment
✔️ WASM Environment
✔️ Terminal Logging
✔️ File Logging
✔️ Network Logging
/* no default feature enabled (enabling both at once won't compile) */
better-logger = { version = "1.0.3", features = ["native"] }
better-logger = { version = "1.0.3", features = ["wasm"] }
use better_logger::LoggerSettings;
/* native settings */
let settings = LoggerSettings {
terminal_logs: true,
terminal_log_lvl: "trace".to_string(),
wasm_logging: false, // must be false
file_logs: true,
file_log_lvl: "error".to_string(),
log_file_path: "/path/to/my/file.log".to_string(),
network_logs: true,
network_log_lvl: "warn".to_string(),
network_endpoint_url: "http://127.0.0.1:8090/".to_string(),
debug_extra: true,
async_logging: false,
};
/* wasm settings */
let settings = LoggerSettings {
terminal_logs: true,
terminal_log_lvl: "debug".to_string(),
wasm_logging: true, // must be true
file_logs: false, // must be false
file_log_lvl: "".to_string(), // value doesn't matter
log_file_path: "".to_string(), // value doesn't matter
network_logs: true,
network_log_lvl: "trace".to_string(),
network_endpoint_url: "https://my.domain.com".to_string(),
debug_extra: true,
async_logging: true, // if network_logs is true, async_logging must also be true
};
use better_logger::logger;
fn main() {
if let Err(err) = logger::init(settings) {
eprintln!("{:?}", err);
std::process::exit(1);
}
}
use better_logger::logger::*;
fn my_function() {
let debug_msg: &str = "world";
let debugx_msg: String = format!(", world");
let fail: &str = r#""failed""#;
trace!("hello");
debug!("{}", debug_msg);
debugx!("hello{}", debugx_msg);
info!("hello message");
warn!("world message");
error!(r#""hello" "world" {}"#, fail);
}
trace!
➡️ (debug!
, debugx!
) ➡️ info!
➡️ warn!
➡️ error!
SETTING | DESCRIPTION |
---|---|
terminal_logs |
Log to terminal |
terminal_log_lvl |
Minimum level to display |
wasm_logging |
Log to dev tools console |
file_logs |
Log to file |
file_log_lvl |
Minimum level to write |
log_file_path |
Path to log file |
network_logs |
Log to an HTTP endpoint |
network_log_lvl |
Minimum level to send |
network_endpoint_url |
URL to send log messages to |
debug_extra |
Show debugx! logs |
async_logging |
Enable async logging |
logger::init()
Can only be called ONCE, subsequent calls will cause a panic!()
File and network logging
uses the same formatting
as the NATIVE console logs
[<RFC 3339 timestamp> <LEVEL> <target>] <message>
log_file_path
requires a local
or absolute
path, a file name only will fail (E.g. log_file_path: "file.log".to_string())
Content-Type
: text/plain; charset=utf-8
synchronous
network logging
NOT allowed in WASM
? Browsers don’t allow blocking network I/O on the main threadfile logging
NOT allowed in WASM
? Browsers can't talk to your file systemformat!()
under the hood, any string-like type is acceptedtesting-wasm
and testing-http
features are for TESTING only
tests/async_native.rs
or tests/sync_native.rs
tests/wasm_environment/main.rs
; this is also the "wasm-test"
binary"http-test"
binary is a simple HTTP server that will print log messages it receivesDEBUGX
?It is just a second debug, the debugx!()
logs will be labeled as DEBUG
when they print
DEBUGX
?Let’s say you’re in development, so you want to see all your debug
logs. However, some of your debug
logs are massive and clutter your terminal.
You can mark those verbose logs as debugx!()
and set debug_extra = false
to hide them.
Later, if you're troubleshooting or need to view them, set debug_extra = true
and see your extra debug logs!
© 2025 Gistyr LLC
This project, better-logger, is dual-licensed under your choice of: