Initial commit
This commit is contained in:
parent
c5a55098b6
commit
e26bdf412e
|
@ -0,0 +1,3 @@
|
||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "beautylog"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Thomas Forgione <thomas@forgione.fr>"]
|
||||||
|
edition = "2018"
|
||||||
|
description = "A beautiful logger in rust"
|
||||||
|
license = "LGPL-3.0-only"
|
||||||
|
repository = "https://gitea.tforgione.fr/tforgione/beautylog"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.4.6"
|
||||||
|
colored = "1.7.0"
|
31
README.md
31
README.md
|
@ -1,3 +1,30 @@
|
||||||
# beautylog
|
# beautylof
|
||||||
|
|
||||||
|
*A beautiful logger in rust*.
|
||||||
|
|
||||||
|
This repository contains the beauty logger. It's based on the [log](https://crates.io/crates/log) crate.
|
||||||
|
|
||||||
|
It is made to be super simple and to mimic the output of rustup and cargo.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
``` rust
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
beautylog::init(log::LevelFilter::Trace).ok();
|
||||||
|
|
||||||
|
info!("some information");
|
||||||
|
warn!("something went wrong");
|
||||||
|
debug!("some debug info");
|
||||||
|
trace!("yo");
|
||||||
|
error!("something went horribly wrong");
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### How it looks like
|
||||||
|
![how it renders](https://gitea.tforgione.fr/attachments/3417667c-746d-4f7f-bb79-c4ffa4913281)
|
||||||
|
|
||||||
|
|
||||||
A beautiful logger in rust
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
beautylog::init(log::LevelFilter::Trace).ok();
|
||||||
|
|
||||||
|
info!("some information");
|
||||||
|
warn!("something went wrong");
|
||||||
|
debug!("some debug info");
|
||||||
|
trace!("yo");
|
||||||
|
error!("something went horribly wrong");
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
//! This crate contains the beauty logger.
|
||||||
|
//!
|
||||||
|
//! It is made to be super simple and to mimic the output of rustup and cargo.
|
||||||
|
//! ### Usage:
|
||||||
|
//! ```
|
||||||
|
//! #[macro_use]
|
||||||
|
//! extern crate log;
|
||||||
|
//!
|
||||||
|
//! fn main() {
|
||||||
|
//!
|
||||||
|
//! beautylog::init(log::LevelFilter::Trace).ok();
|
||||||
|
//!
|
||||||
|
//! info!("some information");
|
||||||
|
//! warn!("something went wrong");
|
||||||
|
//! debug!("some debug info");
|
||||||
|
//! trace!("yo");
|
||||||
|
//! error!("something went horribly wrong");
|
||||||
|
//!
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! ### How it looks like
|
||||||
|
//! ![how it renders](https://gitea.tforgione.fr/attachments/3417667c-746d-4f7f-bb79-c4ffa4913281)
|
||||||
|
//!
|
||||||
|
|
||||||
|
use log::{Record, Level, Metadata, SetLoggerError, LevelFilter};
|
||||||
|
use colored::*;
|
||||||
|
|
||||||
|
struct BeautyLogger;
|
||||||
|
static LOGGER: BeautyLogger = BeautyLogger;
|
||||||
|
|
||||||
|
/// Initializes the beauty logger with the corresponding level filter.
|
||||||
|
pub fn init(level: LevelFilter) -> Result<(), SetLoggerError> {
|
||||||
|
log::set_logger(&LOGGER)
|
||||||
|
.map(|()| log::set_max_level(level))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl log::Log for BeautyLogger {
|
||||||
|
fn enabled(&self, _: &Metadata) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log(&self, record: &Record) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
match record.level() {
|
||||||
|
Level::Error => eprintln!("{} {}", "error:".bold().red(), record.args()),
|
||||||
|
Level::Warn => eprintln!("{} {}", "warning:".bold().yellow(), record.args()),
|
||||||
|
Level::Info => eprintln!("{} {}", "info:".bold(), record.args()),
|
||||||
|
Level::Debug => eprintln!("{} {}", "debug:".bold().blue(), record.args()),
|
||||||
|
Level::Trace => eprintln!("{} {}", "trace:".bold().cyan(), record.args()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) {}
|
||||||
|
}
|
Loading…
Reference in New Issue